私は次のMySQL
クエリを持っています:
SELECT
s.student_id, s.student_firstname, s.student_lastname, s.isActive,
c.city_name,
sd.student_startdate, sd.student_enddate,
SUM(scpe.scpe_estemated_days) AS total
FROM students s
INNER JOIN cityselections c ON c.city_id = s.student_city_id
INNER JOIN studentdates sd ON sd.student_id = s.student_id
LEFT JOIN studentcourseplan scp ON scp.student_id = s.student_id
LEFT JOIN studentcourseplanelements scpe ON scpe.scpe_cpl_id = scp.cpl_id
GROUP BY scp.cpl_id
これは出力できます:
+------------+-------------------+------------------+----------+------------+-------------------+-----------------+-------+
| student_id | student_firstname | student_lastname | isActive | city_name | student_startdate | student_enddate | total |
+------------+-------------------+------------------+----------+------------+-------------------+-----------------+-------+
| 83 | John | Doe | 1 | Dallas | 2012-07-23 | 2012-09-30 | 413 |
| 84 | Derp | Derpson | 1 | Texas | 2012-07-01 | 2012-08-26 | 413 |
| 85 | Barack | Obama | 1 | Washington | 2012-08-02 | 2012-08-31 | 2 |
| 85 | Barack | Obama | 1 | Washington | 2012-08-02 | 2012-08-31 | 153 |
+------------+-------------------+------------------+----------+------------+-------------------+-----------------+-------+
total
ここで、それぞれの列の値が最も高い行のみを印刷したいと思います。student_id
試しMySQL
MAX()
ましたが、うまくいきませんでした。
それはどのように行われるべきですか?