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])

解决方案 »

  1.   

      
    where后面不能跟sum
      

  2.   

    测试数据如下:
    表一(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
      

  3.   


    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.数量)
      

  4.   

       刚才打错了
    谢谢 5 楼 chwnrthd 的回复
      

  5.   

    SELECT a.[ID] FROM (SELECT [ID]
          ,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