我有这样的声明:
SELECT COUNT(ID) AS numberVote, AWARD_ID, NOMINEE_ID, VOTER_ID, MULTI_CODE
FROM b_awards_vote
WHERE AWARD_ID = 8
GROUP BY MULTI_CODE
我的表格如下:
ID | AWARD_ID | NOMINEE_ID | VOTER_ID | MUTLI_CODE
1 | 8 | 3 | 1 | 4837
2 | 8 | 4 | 1 | 4837
3 | 8 | 5 | 1 | 4837
然而在php中返回:
$numberVote = $row['numberVote'];
此声明返回3.以下是我想要的更多细节:
所以上表中的这个例子我想算作1票。在下表中:
ID | AWARD_ID | NOMINEE_ID | VOTER_ID | MUTLI_CODE
1 | 8 | 3 | 1 | 4837
2 | 8 | 4 | 1 | 4837
3 | 8 | 5 | 1 | 4837
4 | 8 | 4 | 3 | 7480
5 | 8 | 5 | 3 | 7480
我希望此计数返回:2因为有两个不同的MULTI_CODE,因为有两组不同的投票。
答案 0 :(得分:3)
此查询将计算您拥有的MUTLI_CODE
群组的数量:
SELECT COUNT( distinct MULTI_CODE) AS NumOfGroups ,ID AS numberVote, AWARD_ID, NOMINEE_ID, VOTER_ID, MULTI_CODE
FROM b_awards_vote
WHERE AWARD_ID = 8
请参阅SQLFiddle以获取参考资料