sql server - SQL Order By with 2 Column - Grouping of Sellers -
sql server - SQL Order By with 2 Column - Grouping of Sellers -
i wanted grouping sellers order cost in sql, let's have below table info me. want order cost first, when seller exist multple time in table should below.(means same sellers together).
table data
sellerid sellername cost 88 flipkart 3950 32 ebay 4139 153 amazon 4139 96 walmart 4388 88 flipkart 5999 153 amazon 4464
requirement :
sellerid sellername cost 88 flipkart 3950 88 flipkart 5999 32 ebay 4139 153 amazon 4139 153 amazon 4464 96 walmart 4388
code below not giving expected result.
select sellerid, sellername, cost tablename order price, sellerid
you can utilize window function min(..) over..
lowest cost each sellername
, sort it.
select sellerid, sellername, cost tablename order min(price) on (partition sellerid), sellerid
sqlfiddle demo sql sql-server sql-server-2008
Comments
Post a Comment