SQL查询无穷无尽

时间:2017-03-29 05:26:41

标签: sql-server

有两个表:
SatisDetay  

Depo    SatisID SatisSira   UrunID    Satici    KdvKod  KDVYuzde    Miktar
AZ01    20001   1           3788898   999       AZ       18.00      1
AZ01    20002   1           3788898   999       AZ       18.00      1
AZ01    20003   1           3876390   999       AZ       18.00      1
AZ01    20003   2           3793202   999       AZ       18.00      1
AZ01    20003   3           4046508   999       AZ       18.00      1
AZ01    20003   4           3843387   999       AZ       18.00      1
AZ01    20003   5           3850608   999       AZ       18.00      1
和DepoSevkDetay

BaslikID    Sira    UrunID   Miktar Fiyat   Depo
20001       1       3792703  1      1       AZ01  
20002       1       4067131  1      1       AZ01  
20003       1       3251881  1      1       AZ01  
20003       2       3251883  1      1       AZ01  
20003       3       3788887  1      1       AZ01  
20003       4       3788890  1      1       AZ01  
20004       1       3761260  2      1       AZ01  

有一项任务是根据每个UrunID获取Miktar的总和,并将其传播到第二个表中的UrunID。但UrunID记录的数量可能不匹配。但这不是唯一的问题。我尝试了一个简单的查询,但它无休止地执行

 UPDATE
    Table_A
SET
    Table_A.[Miktar] = Table_B.[Miktar]
FROM
    [Retail].[dbo].[tb_DepoSevkDetay] AS Table_A
    INNER JOIN (
                SELECT [Miktar], [UrunID] FROM [Retail].[dbo].[tb_SatisDetay]
                GROUP BY [UrunID], [Miktar] ) AS Table_B
        ON Table_A.[UrunID] = Table_B.[UrunID]

请帮助找出原因

0 个答案:

没有答案