日期:2014-05-17 浏览次数:20472 次
CREATE TABLE tb(col1 VARCHAR(50))
INSERT INTO tb(col1)
SELECT 'YANGSH001' UNION ALL SELECT 'YANGSH002' UNION ALL SELECT 'YANGSH005' UNION ALL
SELECT 'YANGSH001' UNION ALL SELECT 'YANGSH002' UNION ALL SELECT 'YANGSH004' UNION ALL
SELECT 'YANGSH001' UNION ALL SELECT 'YANGSH002' UNION ALL SELECT 'YANGSH003' UNION ALL
SELECT 'YANGSH001' UNION ALL SELECT 'YANGSH003' UNION ALL SELECT 'YANGSH004'
--排序结果应该是下面的这种形式
col1
YANGSH001
YANGSH001
YANGSH001
YANGSH001
YANGSH002
YANGSH002
YANGSH002
YANGSH003
YANGSH003
YANGSH004
YANGSH004
YANGSH005
--这里003跟004数目一样,就无所谓哪个排在前面了,最好是小的再前面
CREATE TABLE tb(col1 VARCHAR(50),col2 VARCHAR(50),col3 VARCHAR(50))
INSERT INTO tb(col1,col2,col3)
SELECT 'YANGSH001','YANGSH014','YANGSH022' UNION ALL
SELECT 'YANGSH001','YANGSH011','YANGSH022' UNION ALL
SELECT 'YANGSH001','YANGSH011','YANGSH022' UNION ALL
SELECT 'YANGSH002','YANGSH011','YANGSH022' UNION ALL
SELECT 'YANGSH002','YANGSH013','YANGSH021' UNION ALL
SELECT 'YANGSH002','YANGSH013','YANGSH021' UNION ALL
SELECT 'YANGSH002','YANGSH013','YANGSH023' UNION ALL
SELECT 'YANGSH003','YANGSH013','YANGSH023' UNION ALL
SELECT 'YANGSH003','YANGSH012','YANGSH023' UNION ALL
SELECT 'YANGSH004','YANGSH012','YANGSH023'
--排序后应是下面这个样子的
col1 col2 col3
YANGSH002 YANGSH013 YANGSH022
YANGSH002 YANGSH013 YANGSH022
YANGSH002 YANGSH013 YANGSH022
YANGSH002 YANGSH013 YANGSH022
YANGSH001 YANGSH011 YANGSH023
YANGSH001 YANGSH011 YANGSH023
YANGSH001 YANGSH011 YANGSH023
YANGSH003 YANGSH012 YANGSH023
YANGSH003 YANGSH012 YANGSH021
YANGSH004 YANGSH014 YANGSH021
--各个列之间还是由多到少排序,不影响
--CREATE TABLE tb1(col1 VARCHAR(50))
--INSERT INTO tb1
-- ( col1
-- )
-- SELECT 'YANGSH001'
-- UNION ALL
-- SELECT 'YANGSH002'
-- UNION ALL