[英]Create Subquery Select for COUNT with JOIN inside the subquery
Have this COUNT subquery but I can't get the syntax to work . 有这个COUNT子查询,但是我无法使用语法。
SELECT products.client_id,
clients.name AS client_name,
cars.vin,
cars.make,
cars.model
(SELECT COUNT(*) FROM manheim_auction_listings AS listings_sub
JOIN products ON
manheim_auction_listings.product_id = products.id
JOIN product_purchases ON
products.current_product_purchase_id = product_purchases.id
WHERE listings_sub.car_id = manheim_auction_listings.car_id AND
listings_sub.id <> manheim_auction_listings.id and
manheim_auction_listings.product_purchase_id =
product_purchases.id) as previous_auction_count
FROM manheim_auction_listings
JOIN cars ON
cars.id = manheim_auction_listings.car_id .....
The (SELECT COUNT(*) will not pass syntax with the JOIN's I Need to get the right count. (SELECT COUNT(*)不会与JOIN的I Need一起传递语法以获得正确的计数。
You are missing GROUP BY
in your inner query. 您在内部查询中缺少GROUP BY
。
WHERE listings_sub.car_id = manheim_auction_listings.car_id AND
listings_sub.id <> manheim_auction_listings.id and
manheim_auction_listings.product_purchase_id =
product_purchases.id
GROUP BY <list_of_column(s)>
Also, there are couple more syntax error(s) 此外,还有另外几个语法错误
You are missing comma ,
just after cars.model
column MUST be separated by ,
. 你缺少逗号,
刚过cars.model
列必须被分开,
。
cars.model
(SELECT COUNT(*) FROM manheim_auction_listings AS listings_sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.