我在尝试按投票次数排序的项目的选择 ID 时遇到了一些麻烦。投票是在单独的表格中进行的,但顺序没有按正确的顺序出现。
谁能指出这是哪里出错了?
表CompetitionEntries
(未在查询中使用,但可能相关)
id | PhotoTitle
=======================
23 | 'Photo 1'
24 | 'Photo 2'
25 | 'Photo 3'
26 | 'Photo 4'
=======================
桌子CompetitionVotes
id | IdOfPhotoVotedOn
=======================
10 | 23
11 | 24
12 | 22
13 | 22
14 | 22
15 | 24
=======================
我正在尝试使用下面显示的语句“
SELECT `IdOfPhotoVotedOn`, COUNT(`IdOfPhotoVotedOn`) 'Votes'
FROM `CompetitionVotes`
WHERE 1
GROUP BY `IdOfPhotoVotedOn`
ORDER BY 'Votes' DESC, `IdOfPhotoVotedOn`
我得到的是
IdOfPhotoVotedOn | Votes
==========================
22 | 3
23 | 1
24 | 2
我想得到的是
IdOfPhotoVotedOn | Votes
==========================
22 | 3
24 | 2
23 | 1