表A
字段1 字段2 字段3 字段4 字段5
1 段线 0 0 0
2 关机 0 0 0
1 段线 0 0 0
3 不通 0 0 0
查询结果这样
字段1 字段2 字段3 字段4 字段5
1 段线 0 0 0
2 关机 0 0 0
3 不通 0 0 0
就是说如果字段1和字段2 如果相同只显示一条 怎么写?谢谢!
字段1 字段2 字段3 字段4 字段5
1 段线 0 0 0
2 关机 0 0 0
1 段线 0 0 0
3 不通 0 0 0
查询结果这样
字段1 字段2 字段3 字段4 字段5
1 段线 0 0 0
2 关机 0 0 0
3 不通 0 0 0
就是说如果字段1和字段2 如果相同只显示一条 怎么写?谢谢!
from 表A
group by 字段1 , 字段2 , 字段3 , 字段4 , 字段5
from 表A
group by 字段1 , 字段2
(select 字段1,字段2,min(id) as id from 表b group by 字段1,字段2) n
where m.字段1 = n.字段1 and m.字段2=n.字段2 and m.id = n.id此出min可以用max
create table ba(c1 int,c2 varchar(10),c3 int,c4 int,c5 int)
insert ba
select 1,'dx',0,0,0
union all
select 2,'gj',0,0,0
union all
select 1,'dx',0,0,0
union all
select 3,'bt',0,0,0select c1 , c2 , max(distinct c3) 字段3 , max(distinct c4 ) 字段4, max(distinct c5 ) 字段5
from ba
group by c1 , c2
order by c1
select 字段1 , 字段2 , max( 字段3) , max( 字段4 ) , max(字段5 )
from 表A
group by 字段1 , 字段2
达到我的目的了 可是 字段3和字段4字段5都显示无列名了
select 字段1 , 字段2 , max( 字段3)as 字段3 ,
max( 字段4 )as 字段4 , max(字段5 )as 字段5
from 表A
group by 字段1 , 字段2