我已经下面的查询给我什么,我wan't(见table_entrees)只能加入一个表中的列与另一个表
SELECT designation, ref1, ref2, ref3, sum(a.qte) AS TotalQte
FROM table_entrees a
WHERE a.ref1 = 'VT2'
GROUP BY a.designation, a.ref1, a.ref2, a.ref3
table_entrees:
designation ref1 ref2 ref3 TotalQte
VT VT2 GRIS L 150
VT VT2 GRIS XL 150
VT VT2 Jaune L 150
VT VT2 Jaune XL 150
和另一个查询相同的第一个,但对于另一个表
SELECT designation, ref1, ref2, ref3, sum(b.qte) AS TotalQte2
FROM table_sorties b
WHERE a.ref1 = 'VT2'
GROUP BY b.designation, b.ref1, b.ref2, b.ref3
table_sorties:
designation ref1 ref2 ref3 TotalQte2
VT VT2 GRIS L 62
VT VT2 JAUNE L 15
但问题是,我已经试过就像下面的表格,它检查是否REF1,REF2,table_sorties的REF3在table_entrees存在两者之间的结合,然后显示出它的结果还显示TotalQte2 0
designation ref1 ref2 ref3 TotalQte TotalQte2
VT VT2 GRIS L 150 62
VT VT2 GRIS XL 150 0
VT VT2 Jaune L 150 15
VT VT2 Jaune XL 150 0
我试过以下查询,但没有给出预期的结果!
SELECT
a.designation,
a.ref1,
a.ref2,
a.ref3,
sum(a.qte) AS TotalQte,
sum(b.qte) AS TotalQte2
FROM FROM table_entrees a,table_sorties b
WHERE a.ref1 = 'VT2'
GROUP BY a.designation, a.ref1, a.ref2, a.ref3
你有可以加入表格的ID列或唯一标识符吗? –