SELECT
Brand.BrandName AS Brand,
COUNT(Auto.Price) AS Count,
CASE WHEN SUM(Auto.Price) THEN SUM(Auto.Price) ELSE 0.0 END AS Price
FROM
Brand
LEFT JOIN
Auto ON Brand.BrandId = Auto.BrandId
GROUP BY
Brand.BrandId
ORDER BY
Brand.BrandName ASC
同样的另一个版本:
SELECT
Brand.BrandName AS Brand,
COUNT(Auto.Price) AS Count,
IFNULL(SUM(Auto.Price), 0.0) AS Price
FROM
Brand
LEFT JOIN
Auto ON Brand.BrandId = Auto.BrandId
GROUP BY
Brand.BrandId
ORDER BY
Brand.BrandName ASC
对于 SQLite3,它将是这样的:
同样的另一个版本:
可能在 aktsese 上它会变成规范。