2017-02-17 51 views
1

我有以下查詢:重複的領域,不同不起作用

select distinct 
    ROW_ID = row_number() over (
    order by wms_us.wms_us.rrno.rrdate 
    , wms_us.wms_us.rrno.pono 
    , wms_us.wms_us.transferboxdet.meidhex 
    , att.Date_cleared 
    ) 
, ATT_PO = wms_us.wms_us.rrno.pono 
, Received_Date = wms_us.wms_us.rrno.rrdate 
, IMEI = case 
     when len(wms_us.wms_us.transferboxdet.meidhex) >= 15 
     then left(wms_us.wms_us.transferboxdet.meidhex, 14) 
     else wms_us.wms_us.transferboxdet.meidhex 
     end 
, Model = case 
     when (wms_us.wms_us.model.modeldesc = 'MIXED') 
     then wms_us.wms_us.transferboxdet.basemodel 
     else wms_us.wms_us.model.modelbase 
     end 
, Date_cleared = case 
     when (Future.[Error Code] = '1') 
     then Future.LocalTime 
     else att.Date_cleared 
     end 
, Result = case 
     when (Future.[Error Code] = '1') 
     then 'PASS' 
     else att.Result 
     end 
from wms_us.wms_us.transferboxdoc 
    inner join wms_us.wms_us.transferboxdet 
    on wms_us.wms_us.transferboxdoc.transferboxdocid 
     = wms_us.wms_us.transferboxdet.transferboxdocid 
    inner join wms_us.wms_us.rrno 
    on wms_us.wms_us.transferboxdet.rrnoid = wms_us.wms_us.rrno.rrnoid 
    inner join wms_us.wms_us.model 
    on wms_us.wms_us.transferboxdoc.modelid = wms_us.wms_us.model.modelid 
    left join DRSCSQLQADB01.att_view2.dbo.attview2 as att 
    on att.IMEI = LEFT(wms_us.wms_us.transferboxdet.meidhex, 14) 
    inner join Futerdial.dbo.Futuredial_Validation as Future 
     on Future.IMEI = wms_us.wms_us.transferboxdet.meidhex 
where (wms_us.wms_us.rrno.rrdate > '2016-12-01') 
    and Future.IMEI = '352130070643357' 

我有IMEI表中Futuredial_Validation重複的,我一直在嘗試使用DISTINCT只是爲了告訴我一個IMEI,但它不工作,有任何替代,我可以使用?或者我使用它錯了? 附上一張展示給我的照片,我只能看到第一張照片。

Screenshot

由於

回答

0

對於行由不同的被濾出,所有的值必須相同。在此查詢中,您可以將查詢包裝在CTE中並在ROW_ID = 1上過濾。