sql - psql max group by just for some columns -


i have problem in psql query. don't know how select maximum value subset of 2 columns. it's hard explain problem without example, write one:

i have table that:

   athlete | category | points        at1  |  cat1    | 100       at1  |  cat1    | 90       at1  |  cat1    | 80       at1  |  cat2    | 95       at2  |  cat1    | 97       at2  |  cat2    | 60       at2  |  cat2    | 71 

i keep every athlete maximum points in every category. final table should that:

   athlete | category | points        at1  |  cat1    | 100       at1  |  cat2    | 95       at2  |  cat1    | 97       at2  |  cat2    | 71 

this classic usecase group by clause return distinct combinations of athlete , category. then, max(points) applied each combination:

select   athlete, category, max(points)     mytable group athlete, category 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -