Alternate Results with ORDER BY clause
CREATE TABLE TEST (
customername varchar(50)
);
INSERT INTO TEST VALUES('CUSTOMER 1');
INSERT INTO TEST VALUES('CUSTOMER 1');
INSERT INTO TEST VALUES('CUSTOMER 1');
INSERT INTO TEST VALUES('CUSTOMER 2');
INSERT INTO TEST VALUES('CUSTOMER 2');
INSERT INTO TEST VALUES('CUSTOMER 2');
SELECT * FROM TEST ORDER BY ???
What ORDER开发者_Python百科 BY clause should I put to get the following result ?:
"CUSTOMER 1"
"CUSTOMER 2"
"CUSTOMER 1"
"CUSTOMER 2"
"CUSTOMER 1"
"CUSTOMER 2"
SELECT customername
FROM TEST
ORDER BY ROW_NUMBER() OVER ( PARTITION BY customername ORDER BY customername )
精彩评论