在sql中重复重复的行

时间:2016-12-01 11:35:20

标签: sql database

我正在尝试执行以下代码行:

select 
    MIN(tr.UPC) as UPC, MIN(td.UPC) as DistUPC,   
    MIN(tr.ProductDescriptionReported) as ProductDescriptionReported,
    MIN(td.ProductDescriptionReported) as DistProdDesc,
    MIN(tr.RawProductIdentifier) as RawProductIdentifier,
    MIN(td.RawProductIdentifier) as DistRawProdIden
--into #tmpCompareData 
from 
    #tmpSTRecData tr
left join 
    #tmpSTDistData td on tr.ChainID = td.ChainID
                      and tr.StoreID = td.StoreID
                      and tr.SupplierID = td.SupplierID
left join 
    TranslationMaster tm on tr.UPC = tm.TranslationCriteria2
group by 
    tr.UPC

enter image description here

我得到了重复的结果行。

在附图中,突出显示的黄色是我得到的,输出绿色突出显示我需要。

请帮助

1 个答案:

答案 0 :(得分:0)

试试这个:

select 
    tr.UPC as UPC, MIN(td.UPC) as DistUPC,   
    MIN(tr.ProductDescriptionReported) as ProductDescriptionReported,
    MIN(td.ProductDescriptionReported) as DistProdDesc,
    MIN(tr.RawProductIdentifier) as RawProductIdentifier,
    MIN(td.RawProductIdentifier) as DistRawProdIden
--into #tmpCompareData 
from 
    #tmpSTRecData tr
left join 
    #tmpSTDistData td on tr.ChainID = td.ChainID
                      and tr.StoreID = td.StoreID
                      and tr.SupplierID = td.SupplierID
left join 
    TranslationMaster tm on tr.UPC = tm.TranslationCriteria2
group by 
    tr.UPC