,我有以下表中的数据:MySQL的计数cccurrence并加入回同桌
ID DrawDate DrawNumber
1 01/01/2014 1234
2 01/01/2014 1235
3 01/01/2014 1236
4 02/01/2014 1237
5 02/01/2014 1234
6 02/01/2014 1238
7 03/01/2014 1234
8 03/01/2014 1235
9 03/01/2014 1239
我想MySQL的计数DrawNumber的发生,并填充回的结果是显示如下:
ID DrawDate DrawNumber Occuurence
1 01/01/2014 1234 3
2 01/01/2014 1235 2
3 01/01/2014 1236 1
4 02/01/2014 1237 1
5 02/01/2014 1234 3
6 02/01/2014 1238 1
7 03/01/2014 1234 3
8 03/01/2014 1235 2
9 03/01/2014 1239 1
我设法拥有以下MYSQL代码,但它似乎将现有数据库的总记录数加倍。
SELECT
DISTINCT table.ID, table.DrawDATE,table.DrawNumber.
(SELECT
COUNT(table.ID)
FROM table
WHERE table1.DrawNumber = table.DrawNumber
) AS Occuurence
FROM table
INNER JOIN table AS table1 ON table.DrawNumber = table1.DrawNumber
ORDER BY table.DrawDATE DESC
任何人都可以建议更好的MySQL查询?
在此先感谢。
CK