如何只取一条负数的记录 CODE, ITEM, QNT --------------- A, 1, -200 A, 2, -80 A, 3, -50 A, 4, 120 A, 5, 260
我想得到的结果是 A, 3, -50 A, 4, 120 A, 5, 260
就是负数的部分我只要抓一条就可以了,前面的可以不要,但正数的我都要
[解决办法] select * from table1 as a where QNT>=0 or not exists(select 1 from table1 where a.QNT<0 and QNT<0 and ITEM>a.ITEM) [解决办法]
+1 [解决办法]
改一下大版的就可以了 select Code,Item,Qnt,(case when Qnt>0 then '' else '*' end) Flag from table1 as a where QNT>=0 or not exists(select 1 from table1 where a.QNT<0 and QNT<0 and ITEM>a.ITEM)