2017-08-08 2 views
0

Ich versuche, Daten aus verschiedenen Tabellen zu exportieren. Ich habe dieselben Header von den Tabellen gezogen.Ich versuche Daten aus verschiedenen Tabellen zu exportieren. Ich habe gleiche Header aus den Tabellen gezogen

wählen LocationID, Menge von a, wählen LocationID, Menge von b, wählen LocationID, Menge von c

Idealerweise möchte ich eine Abfrage meine Daten sehen, wie LocationID qtyA qtyB

qtyc

Könnte mir jemand mit SQL Query helfen?

+0

Versuchen Sie es mit 'Join'. 'wähle locationid, qtyA, qtyB, qtyC aus einem Join b auf a.locationid = b.locationid join c auf c.locationid = b.locationid;' – Mekicha

Antwort

1

Können Sie die folgenden Abfragen versuchen?

Zuerst in ANSI-89:

SELECT 
a.locationid as locationIdA, a.qty as qtryA, 
b.locationid as locationIdB, b.qty as qtryB, 
c.locationid as locationIdC, c.qty as qtryC 
FROM 
a, b, c 

Falls Sie von LocationID filtern müssen (verbunden):

SELECT 
a.locationid as locationIdA, a.qty as qtryA, 
b.locationid as locationIdB, b.qty as qtryB, 
c.locationid as locationIdC, c.qty as qtryC 
FROM 
a, b, c 
WHERE 
a.locationid=b.locationid 
AND 
b.locationid=c.locationid 

Auch Sie könnten versuchen, mit ANSI-92:

SELECT 
a.locationid as locationIdA, a.qty as qtryA, 
b.locationid as locationIdB, b.qty as qtryB, 
c.locationid as locationIdC, c.qty as qtryC 
FROM 
a 
INNER JOIN b 
ON 
a.locationid=b.locationid 
INNER JOIN c 
ON 
a.locationid=c.locationid 
Verwandte Themen