我正在嘗試做一個需要group by的count查詢。但是當我得到我的結果時,我得到了正確數量的行,但他們的總數列中的計數,而不是我想要的行數量。用組數來計算,返回行數
SELECT Count(p.products_id) AS total
FROM products p
LEFT JOIN specials s
ON p.products_id = s.products_id
LEFT JOIN manufacturers m
ON p.manufacturers_id = m.manufacturers_id
JOIN products_description pd
ON p.products_id = pd.products_id
JOIN products_to_categories p2c
ON p.products_id = p2c.products_id
INNER JOIN products_specifications ps7
ON p.products_id = ps7.products_id
LEFT JOIN products_to_icon p2i
ON p.products_id = p2i.products_id
LEFT JOIN products_icons pi
ON p2i.icons_id = pi.icons_id
WHERE p.products_status = '1'
AND pd.language_id = '1'
AND ps7.specification IN ('Polycotton')
AND ps7.specifications_id = '7'
AND ps7.language_id = '1'
GROUP BY p.products_id
我能做些什麼來使它給我總行數,而不是將每個產品ID的總數分組爲總數。
什麼樣我得到的:
total
1
2
1
1
2
2
我想要什麼:
total
6
當前計數是否可以包含0?如果是這樣,總數應該包括那一行嗎? –