2012-11-08 27 views
0

我需要藝術家MySQL的 - 計數問題

SELECT artist, 
    title, 
    label, 
    COUNT(title) AS countTitles 
FROM table 
WHERE domain = 'domain.com' 
GROUP BY title 
ORDER BY countTitles DESC; 

算冠軍,但結果只得到了我的稱號計數 - 與不同的藝術家。

我想:

artist1 - title1a 
artist1 - title2a 
artist1 - title1a 
artist1 - title1a 
artist1 - title1a 

我想算這樣

artist1 - title1a - 4 
artist1 - title2a - 1 

我到底做錯了什麼?

回答

1

你不應該選擇哪些是不是在你的GROUP BY列,即使MySQL的擴展了這個。

SELECT artist, title, 
    COUNT(*) AS countTitles 
FROM table 
WHERE domain = 'domain.com' 
GROUP BY artist, title 
ORDER BY countTitles DESC; 
+0

什麼ü意味着什麼?我不應該選擇標籤,如果我不在組中使用它? –

+0

@ Dev-Ria完全正確。 – Kermit

+0

有趣。它有什麼作用?減慢查詢速度? –