SQL语句怎么写呀?

ytc1977 2002-12-19 10:40:31
有A、B、C三个表。
A有:a1,a2字段
B有:a1,b1字段
C有:a1,c1字段
select (a2-b1-c1) as 余额 from A,B,C where A.a1=B.a1 and A.a1=C.a1
我想实现当B或C中没有a1,而A表中a1肯定都有的时如:
select (a2-b1) as 余额
select (a2-c1) as 余额
select a2 as 余额
一条SQL语句怎么写呀?
急用,谢谢了!

...全文
94 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
softrookie 2002-12-19
  • 打赏
  • 举报
回复
试试
where c.a1 not in (select a.a1 from a,b where a.a1=b.a1)
where b.a1 not in (select a.a1 from a,c where a.a1=c.a1)
from a where (a1 not in (select a1 from b)) and (a1 not in (select a1 from c))

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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