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 ???
我应该使用什么ORDER BY子句来获得以下结果?:
"CUSTOMER 1"
"CUSTOMER 2"
"CUSTOMER 1"
"CUSTOMER 2"
"CUSTOMER 1"
"CUSTOMER 2"
答案 0 :(得分:12)
SELECT customername
FROM TEST
ORDER BY ROW_NUMBER() OVER ( PARTITION BY customername ORDER BY customername )