sql - Select all rows based on alternative publisher -


i want list rows alternative publisher price ascending, see example table below.

id publisher   price 1    abc       100.00 2    abc       150.00 3    abc       105.00  4    xyz       135.00        5    xyz       110.00 6    pqr       105.00 7    pqr       125.00 

the expected result be:

id publisher   price 1    abc       100.00 6    pqr       105.00 5    xyz       110.00 3    abc       105.00 7    pqr       125.00 4    xyz       135.00        2    abc       150.00  

what required sql?

this should it:

select id, publisher, price (   select id, publisher, price,          row_number() on (partition publisher order price) rn   publisher ) t order rn, publisher, price 

the window functions assigns unique numbers each publisher price. based on outer order first display rows rn = 1 rows each publisher lowest price. second row each publisher has second lowest price , on.

sqlfiddle example: http://sqlfiddle.com/#!4/06ece/2


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -