SELECT t.id_type, brand, model, countMod FROM types t
LEFT JOIN (
SELECT p.id_type, brand, model, COUNT( model ) AS countMod
FROM products p
GROUP BY brand) p2
ON t.id_type = p2.id_type
WHERE t.id_type = "TCE"
ORDER BY brand
このクエリは問題なく機能しますが、もちろん、各ブランドの下にグループ化されたモデルを失います。
モデルをリストしてカウントする方法はありますか?
つまり、brand1、model1、model2、model3、countMod=3 -- brand2、model1、model2、countMod=2 です。
どんな助けでも大歓迎です。ありがとう