distinct语句

来源:百度知道 编辑:UC知道 时间:2024/09/20 23:33:15
select distinct(类型编号),仪器编号 from tem_zd where 类型编号 is not null
select 仪器编号,distinct(类型编号) from tem_zd where 类型编号 is not null
我想把类型放到第2列可以吗 上面那样写会抱错

distinct只能放到查询列的最前边

distinct后面的括号是多余的
正确的写成这样
select distinct 类型编号,仪器编号 from tem_zd where 类型编号 is not null
select distinct 仪器编号,类型编号 from tem_zd where 类型编号 is not null

看来你还不清楚distinct和group的区别

distinct是一摸一样的时候才会将两行合并
也就是说
1 0001 1234
1 0001 4321
这两行并不会合并只对于
1 0001 1234
1 0001 1234
这两行才会合并

DISTINCT语句用来指定在结果集中只显示唯一行.空值被认为相等.语句的话就是第一个回答中写的那样.不明白的话可以去联机丛书找用法.