2017-08-08 30 views
0

我想从不同的表中导出数据。我从表格中拉出了相同的标题。我正试图从不同的表中导出数据。我从表中拉相同的标头

选择locationid,从数量, 选择locationid,从B货, 选择locationid,从C

理想我想进行查询,看看我的数据 locationid qtyA qtyB qtyc

数量有人可以帮我用SQL查询吗?

+0

尝试使用'join'。 '从a.locationid上的连接b中选择locationid,qtyA,qtyB,qtyC = c.locationid = b.locationid; – Mekicha

回答

1

您可以尝试以下查询吗?

首先在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 

在你需要locationId过滤的情况下(加入):

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 

你也可以尝试用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 
相关问题