sql语句

1825 2002-12-22 11:23:53
怎样找出数量既有正数的也有负数的单据?
单号 数量
1 10
1 20
2 1
2 -5
3 1
......
怎样select 出2?
...全文
90 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
1825 2002-12-22
  • 打赏
  • 举报
回复
select 单号
from table
group by 单号
having sum(distinct case when 数量>0 then 1 else -1 end) = 0

pengdali(大力) ??

pengdali 2002-12-22
  • 打赏
  • 举报
回复
呵呵!
楼主0呢!?
1825 2002-12-22
  • 打赏
  • 举报
回复
select 单号
from table
group by 单号
having count(distinct case when 数量>0 then 1 else -1 end) = 0

谢谢你!
Chiff 2002-12-22
  • 打赏
  • 举报
回复
select 单号
from table
group by 单号
having count(distinct case when 数量>0 then 1 else -1 end) = 2
Chiff 2002-12-22
  • 打赏
  • 举报
回复
select 单号
from table
group by 单号
having sum(distinct case when 单号>0 then 1 else -1 end) = 2

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧