使用distinct用于指定字段去重,返回指定字段的唯一值
select * from ZJDJS
distinct必须写在开头
select distinct shbh as h from ZJDJS
distinct后面的都是去重列,效果是distinct后面(字段一+字段二+字段...)综合起来唯一
select distinct dl,shbh as h from ZJDJS
distinct后面的去重字段可以起别名
select distinct dl,shbh as h from ZJDJS
distinct可以用在统计函数
select count(distinct shbh) as h from ZJDJS
但是不能只加括号,这种方式会报错
select (distinct shbh) from ZJDJS
select (distinct shbh),dl from ZJDJS