1、我们知道,SQL语句中用count函数统计记录数量,配合distinct关键字可以统计非重复的记录数量。例如:
select count(*), count(city_name), count(distinct city_name) from tb_county
- 1
查询结果是:
count(*) | count(city_name) | count(distinct city_name) |
---|---|---|
2534 | 2534 | 363 |
select count(*), count(city_name), count(distinct city_name)
from tb_county
where xs_code like '23%'
or xs_code like '24%'
- 1
- 2
- 3
- 4
查询结果是:
count(*) | count(city_name) | count(distinct city_name) |
---|---|---|
85 | 85 | 16 |