mysql - SQL ORDER BY but also by MIN of different col (aka threading)? -


regarding example data below, order type each resulting group order min(valu) without aggregation.

  type valu   ---- ----   b    12     b    88     b    200    b    200       56        100       100    c    70     c    70   

so records of type b listed first because group has record containing lowest valu (12). type records because of record valu 56 , type c records because of record valu(s) 70.

is there way type of sorting in sql?

to explain further, if programmatically, might first sort records type , secondarily valu decending. need sort groups of records valu of first record of each group.

so like:

  select type, valu data order type, valu 

gets me of way there. want sort groups lowest valu.

this might compared "threading" posts in forum posts same subject grouped groups sorted date of latest post within group (although threading forum posts more complex because sorting done reply order whereas in example want sort numerically valu).

is there way in sql? if not, , need programmatically, there @ least query yield latest records , records of same type limit not have retrieve records? if there 2 records of same type 1 low valu , other vary high valu, limit clause might exclude record high valu.

get types min values in subquery , rejoin table. can order of type-groups min value.

select     table.type,     table.value (     select          type,         min(value) minvalue     table     group type ) sub inner join table     on table.type = sub.type order sub.minvalue asc, table.type asc, table.value asc 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -