开发者

Subselect in a Join - Problem

开发者 https://www.devze.com 2023-02-13 17:18 出处:网络
I\'ve a little Problem with a statement: SELECT p1.Modell_nr, p1.ProductID, p2.count_modlieffarbe_vl, 开发者_JAVA百科concat(p1.Modell_nr,\'_\',p1.LiefFarbe) as modfarb_id1

I've a little Problem with a statement:

SELECT 
    p1.Modell_nr, 
    p1.ProductID,
    p2.count_modlieffarbe_vl,
 开发者_JAVA百科   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 

... it works without error-message. ... but get only Modell_nr, ProductID and modfarb_id1 as cols in my results. Why I dont see count_modlieffarbe_vl in my results?


I would say becouse it isn't in p2 table. Your query should look like this:

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 is the key.

0

精彩评论

暂无评论...
验证码 换一张
取 消