我的陈述有点问题:
SELECT
p1.Modell_nr,
p1.ProductID,
p2.count_modlieffarbe_vl,
concat(p1.Modell_nr,'_',p1.LiefFarbe) as modfarb_id1
FROM produkte as p1
LEFT JOIN
(
SELECT p2.ProductID as tester,
count(*) as count_modlieffarbe_vl
FROM produkte as p2
WHERE p2.Vl>p2.vl_min
group by p2.Modell_nr, p2.LiefFarbe
) as count_modlieffarbe_vla ON p1.ProductID = tester
...它没有错误信息。 ...但在我的结果中只获得Modell_nr,ProductID和modfarb_id1作为cols。为什么我在结果中看不到count_modlieffarbe_vl?
答案 0 :(得分:1)
我想说因为它不在p2表中。您的查询应如下所示:
SELECT
p1.Modell_nr,
p1.ProductID,
count_modlieffarbe_vla.count_modlieffarbe_vl,
concat(p1.Modell_nr,'_',p1.LiefFarbe) as modfarb_id1
FROM produkte as p1
LEFT JOIN
(
SELECT p2.ProductID as tester,
count(*) as count_modlieffarbe_vl
FROM produkte as p2
WHERE p2.Vl>p2.vl_min
group by p2.Modell_nr, p2.LiefFarbe
) as count_modlieffarbe_vla ON p1.ProductID = tester
count_modlieffarbe_vla.count_modlieffarbe_vl 是关键。