-1
我有一個來自mySQL的問題,實際上我想顯示學生的最高票數在學科全名。 這裏的代碼MySQL - 顯示最高的投票
$query="SELECT student_tbl.fullname, student_tbl.subject,
COUNT(student_tbl.fullname)AS rating
FROM student_tbl
INNER JOIN subject_tbl
ON student_tbl.subject= subject_tbl.subjname
GROUP BY subject ORDER BY num,
COUNT(fullname) DESC";
student_tbl subject_tbl
| fullname | subject| | subjname | num |
==================== ================
| John | Math | | Math | 1 |
| Rey | Math | | Science | 2 |
| Wey | Science | | English | 3 |
| Xin | Science | =================
| Nick | English |
| Mi | English |
| John | Math |
| Xin | Science |
| Mi | English |
======================
下面是輸出到我的代碼:
| fullname | Subject | Votes |
============================
| John | Math | 2 |
| Wey | Science | 2 |
| Nick | English | 2 |
,這是我想要的輸出:
| fullname | Subject | Votes |
============================
| John | Math | 2 |
| Xin | Science | 2 |
| Mi | English | 2 |
看到,因爲你的受試者(大概)一個'num'的PK表,你爲什麼那麼存儲'subjname'旁邊的學生'fullname'?另外,你在第一個表上缺少一個重要的主鍵。 – Strawberry