sql - Minimum value of a column corresponding to another column value -


i have data table below pulling data base

  type   week  amount       201304  77       201304  77       201304  77       201304  77       201304  71       201304  71       201305  77       201305  77       201305  77       201305  77       201305  77       201305  77 

i trying pull minimum value amount column every week only, table should

  type   week  amount       201304  71       201305  77 

thank you help

what's wrong regular group by?

select type, week, min(amount) amount table_name group type, week 

edit

if have different types in same week same amount, want do? if want know type has min(amount) in week:

select distinct t2.*  (select week, min(amount) amount     table_name     group week) t1   join table_name t2 on t1.amount = t2. amount , t1.week = t2.week 

Comments