select a.id from [表一] a inner join [表二] b on a.id=b.id inner join [表三] c on a.id=c.id
where sum(a.id)<>(b.[字段2]-c.[字段3])
where sum(a.id)<>(b.[字段2]-c.[字段3])
解决方案 »
- 更新表的时候,如何让每条记录日期不重复
- 这样的SQL查询语句怎么写,我问都不会问::::
- SQL问题求解
- 求SQL语句一条,在线等!
- 求一SQL
- 请问用什么命令来查看SQL Server 里有什么具体数据库和每个数据库里有些什么表?
- 消息 137,级别 15,状态 2,第 2 行 必须声明标量变量 "@sql2"。
- 求救:VC+ADO+mdb+sql查询出错,帮忙!!!
- SQL问题:如何提取需要的数据
- 在线报表采集汇总系统
- 我现在有一张User表 一张业务数据表Business 。Business 有2个UserID相关字段 创建人 和更新者。
- sql server 2005 出现"出现未指定的错误"
where后面不能跟sum
表一(ID 出库数量)
00001 50
00001 50
00001 40
00002 50
00002 60
00002 50
00003 100
00003 100表二(ID 入库数量)
00001 200
00002 200
00003 500表三(ID 库存数量)
00001 60
00002 40
00003 300
create table test1(ID nvarchar(10),数量 int)
insert test1
select '00001',50 union all
select '00001',50 union all
select '00001',40 union all
select '00002',50 union all
select '00002',60 union all
select '00002',50 union all
select '00003',100 union all
select '00003',100
create table test2(ID nvarchar(10),数量 int)
insert test2
select '00001',200 union all
select '00002',200 union all
select '00003',500
create table test3(ID nvarchar(10),数量 int)
insert test3
select '00001',60 union all
select '00002',40 union all
select '00003',300select *
from (
select ID,数量=SUM(数量)
from test1
group by ID
) a
inner join test2 b
on a.ID=b.ID
inner join test3 c
on a.ID=c.ID
where a.数量<>(b.数量-c.数量)
谢谢 5 楼 chwnrthd 的回复
,Sum([Val]) as [Val]
FROM Table_1 GROUP BY [ID])as a,
(SELECT b.[ID],(b.[Val]-c.[Val]) as [Val] FROM Table_2 as b,Table_3 as c
WHERE b.[ID]=c.[ID]) as b
WHERE a.[ID]=b.[ID] and a.Val<>b.Val