How to get latest index of GROUP BY in mysql query? -
i got confused algorithm , way latest index of group by. have query this.
select hasil_kmbg result, extract(month tgl_check) month, extract(year tgl_check) year perkembangan no_pasien=11 group month, id_kmbg desc
and here result of query
|result|month|year| ------------------- |3 |1 |2013| |1 |1 |2013| |5 |1 |2013| |1 |2 |2013| |1 |3 |2013| , on
the question is, how result result 3 in month 1? didn't want show other result int month 1 except 3 (the latest, order desc).
you getting multiple rows per month because have included id_kmbg
in group by
clause. think want max()
function:
select max(hasil_kmbg) result, extract(month tgl_check) month, extract(year tgl_check) year perkembangan no_pasien=11 group month, year;
Comments
Post a Comment