像咨询一个挠头的sql语句,在线等待。谢谢了

linxiaozhi 2003-11-15 09:38:06
有这样两个表
表A money 表 B money
20 20
22 25
28 28
28 30
30 30
31 31
31 31

我希望能对两个表做比较,结果是得到存在在表A中的而不在表B中的钱数,如22
以及钱数和个数没有完全对应的钱数,如28 30

谢谢
...全文
28 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-11-15
  • 打赏
  • 举报
回复
select identity(int,1,1) id,* into #a from a
select identity(int,1,1) id,* into #b from b

select * from (
select (select count(*) from #a where [money]=tem.[money] and id<=tem.id) id,[money] from #a tem) a
where not exists (select 1 from (
select (select count(*) from #a where [money]=tem.[money] and id<=tem.id) id,[money] from #a tem) b
where a.id=b.id and a.[money]=b.[money])

drop table #a,#b
samuelpan 2003-11-15
  • 打赏
  • 举报
回复
Select * From A Where Money In
(Select money from
(select money,count(*) cnt from A group by money) a,
(select money,count(*) cnt from B group by money) b
Where a.money=b.money and a.cnt!=b.cnt
)
linxiaozhi 2003-11-15
  • 打赏
  • 举报
回复
???
select 1 ???

是什么意思呀?
linxiaozhi 2003-11-15
  • 打赏
  • 举报
回复
money 是货币类型的字段
samuelpan 2003-11-15
  • 打赏
  • 举报
回复
select * from A where not exists(select 1 from B where money=A.Money)
linxiaozhi 2003-11-15
  • 打赏
  • 举报
回复
我的表就只有一列而已
pengdali 2003-11-15
  • 打赏
  • 举报
回复
你的表就只有一列?给出表结构。

34,623

社区成员

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

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