求解一条SQL语句写法
select * into # from(
select 'E12E9CF5-2FBF-A9E3-B91E-0B926D71B12D' a, 1 b union all
select '8C284328-ED7F-03B0-57E8-2337997B0C8B', 3 union all
select '8C284328-ED7F-03B0-57E8-2337997B0C8B', 7
)z
select * from #
中间第二条与第三条数据相同,我想按照B列的值来计算,当a列数据相同时,就取B值较小的一行数据。
我想要得到的结果是 :
select 'E12E9CF5-2FBF-A9E3-B91E-0B926D71B12D' a, 1 b union all
select '8C284328-ED7F-03B0-57E8-2337997B0C8B', 3
谢谢!
------解决方案--------------------select a,min(b)b from # group by a
------解决方案--------------------select * from # t where NOT EXISTS(SELECT 1 FROM # WHERE t.a=a AND t.b>b)