考虑下表
我需要按降序返回一个列表,其中 member_nr的数量在表where tournament = 'EPL' AND ROUND = '12'
示例
该脚本应返回以下结果:
我想到了这个问题,我的逻辑问题就是这样的
第一步:GET member_nr逐一
$sql = "SELECT DISTINCT *
FROM winners
WHERE tournament='$tour' AND round='$round'";
LOOP(){ //get 1 member number
$mem_nr = ['mem_nr']; //assign mem_nr to variable
第2步:获取计数(次数)^ ABOVE ^会员编号出现在表格中
"$sql="SELECT *, count(member_nr) as nrWins
FROM winners
where member_nr ='$memNr' and tournament='$tournament' AND round='$round'";"
LOOP(){//get count
第3步:显示数据
echo $row=['nrWins'] //Display Number Wins
echo $memNr
}//END LOOP
}//END LOOP
我的问题:
以上对我来说似乎不是很有效,我正在寻找最简单有效的方法来返回上表中的会员数量,欢迎任何想法/建议
答案 0 :(得分:3)
尝试这样的事情:
SELECT *, COUNT(*) AS `wins`
FROM `winners`
WHERE `tournament` = '$tournament'
AND `round` = '$round'
GROUP BY `member_nr`
ORDER BY `wins` DESC
答案 1 :(得分:2)
IEnumerable