2015-10-22 39 views
0

我不知道如何重寫查詢以避免ISPRIMARY = 0的記錄。換句話說,允許的值必須是ISPRIMARY = 1和ISPRIMARY = NULL。在orden中重寫查詢以避免某些記錄

查詢是下一個:

select 
    S.assetnum, S.description, S.serialnum, 
    S.epp_codactfij, S.location, L.description, 
    S.EPP_NUMCONTRATO, S.PURCHASEPRICE, U.personid, U.isprimary 
from maximo.asset S 
left join maximo.locations L on S.location=L.location 
left join maximo.assetusercust U on S.assetnum=U.assetnum 
where 
S.siteid ='TI' 
order by S.assetnum 
+0

它的工作原理!非常感謝 –

回答

0
select 
    S.assetnum, S.description, S.serialnum, S.epp_codactfij, 
    S.location, L.description, S.EPP_NUMCONTRATO, 
    S.PURCHASEPRICE, U.personid, U.isprimary 
from maximo.asset S 
left join maximo.locations L on S.location=L.location 
left join maximo.assetusercust U on S.assetnum=U.assetnum 
WHERE S.siteid ='TI' AND (U.isprimary = 1 OR U.isprimary IS NULL) 
order by S.assetnum; 

或:

select 
    S.assetnum, S.description, S.serialnum, S.epp_codactfij, 
    S.location, L.description, S.EPP_NUMCONTRATO, 
    S.PURCHASEPRICE, U.personid, U.isprimary 
from maximo.asset S 
left join maximo.locations L on S.location=L.location 
left join maximo.assetusercust U on S.assetnum=U.assetnum 
WHERE S.siteid ='TI' AND (U.isprimary <> 0 OR U.isprimary IS NULL) 
order by S.assetnum; 
+0

非常感謝 –

1

嘗試添加以下行WHERE條款:

select 
S.assetnum, S.description, S.serialnum, S.epp_codactfij, S.location, L.description, S.EPP_NUMCONTRATO, S.PURCHASEPRICE, U.personid, U.isprimary 
from maximo.asset S 
left join maximo.locations L on S.location=L.location 
left join maximo.assetusercust U on S.assetnum=U.assetnum 
where 
S.siteid ='TI' 
-- add this line 
AND (U.isprimary = 1 OR U.isprimary IS NULL) 
order by S.assetnum 
+0

請問爲什麼要添加與已發佈的答案相同的答案? – lad2025

+0

當他發佈時,我正處在寫作中,哈哈。 – McGlothlin

+0

我對本頁的看法認爲這是最早的答案,1分鐘。 –