开发者

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 )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜