CREATE TABLE #tab( col VARCHAR(1) NOT NULL ,col2 INTEGER...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

CREATE TABLE #tab(
   col  VARCHAR(1) NOT NULL 
  ,col2 INTEGER  NOT NULL
  ,col3 INTEGER  NOT NULL
);
INSERT INTO #tab(col,col2,col3) VALUES
 ('a',1,15)
,('a',2,3)
,('a',3,34)
,('b',1,55)
,('b',2,44)
,('b',3,8);


SELECT *
FROM #tab
ORDER BY SUM(col3) OVER(PARTITION BY col) DESC,
         col2

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results