2016-11-08 4 views
0
select itemcode,description,location,stocklevel,wtavg_cost,dddvalue  
    from hms_pha_stock c 
    where c.stocklevel>0 
    and itemcode not in 
    (
     select itemcode 
     from hms_pha_tranheader a, hms_pha_transaction b 
     where a.refno = b.refno 
     and a.trantype = b.trantype 
     and a.trantype in ('PTO','PIS') 
     and b.location ='CPH' and a.transdate between '2016-11-01' and '2016-11-08' 
    ) 
    and c.location ='CPH' 
    group by itemcode 
+1

einen Fehler zeigen in dieser Abfrage lösen? –

Antwort

0

Sie haben subquery in where-Klausel verwendet. Dort können Sie nur eine Spalte auswählen, um die Bedingung der where-Klausel zu erfüllen.

Im Folgenden werde ich die Abfrage nach für Ihre Anforderung geändert haben

SELECT c.itemcode, 
     description, 
     location, 
     stocklevel, 
     wtavg_cost, 
     dddvalue 
FROM hms_pha_stock c 
LEFT JOIN (SELECT itemcode, transdate 
      FROM hms_pha_tranheader a, 
        hms_pha_transaction b 
      WHERE a.refno = b.refno 
        AND a.trantype = b.trantype 
        AND a.trantype IN ('PTO', 'PIS') 
        AND b.location = 'CPH' 
        AND a.transdate BETWEEN 
         '2016-11-01' AND '2016-11-08') lJoin 
ON c.itemcode = lJoin.itemcode 
WHERE c.stocklevel > 0 
     AND lJoin.itemcode IS NULL 
     AND c.location = 'CPH' 
GROUP BY c.itemcode 

Hoffnung sollte dies Ihr Problem

+0

Vielen Dank, es gibt mir einen Fehler mehrdeutigen Feldes, aber ich habe einen Alias ​​hinzugefügt –

+0

Wenn die Antwort Ihr Problem löst, machen Sie es bitte als eine richtige Antwort, die für andere hilfreich wäre. – Viki888

+0

Das hat jetzt erfolgreich funktioniert, Danke. –

Verwandte Themen