mysql - do the data aggregation with min value of other field -
i have 1 table in mysql database.
name age code foo 24 23 bar 23 21 mit 19 23
and doing data aggregation on basis of "code"
attribute, using "group by"
in mysql this
select * table group code
output
foo 24 23 bar 23 21
i interested in aggregated result min age.
expected output
mit 19 23 bar 23 21
i looking optimized query that.
thanks in advance. please let me know if need more detail.
you want row has minimum age each code. means there no smaller age code. here 1 method:
select t.* table t not exists (select 1 t2 t2.code = t.code , t2.age < t.age);
Comments
Post a Comment