拥有此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 .....
(SELECT COUNT(*)不会通过JOIN传递语法我需要得到正确的计数。
答案 0 :(得分:0)
您的内部查询中缺少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)>
此外,还有更多语法错误
在,
列 必须 被cars.model
分隔后,您将丢失逗号,
。
cars.model
(SELECT COUNT(*) FROM manheim_auction_listings AS listings_sub