Code1 VARCHAR(10),
Code2 VARCHAR(7)
)
go
INSERT INTO #temp
SELECT '330200101', '3302001' UNION ALL
SELECT '330200102', '3302001' UNION ALL
SELECT '330200103', '3302001' UNION ALL
SELECT '330200105', '3302001' UNION ALL
SELECT '330200201', '3302002' UNION ALL
SELECT '330200202', '3302002' UNION ALL
SELECT '330200203', '3302002' UNION ALL
SELECT '330200204', '3302002' UNION ALL
SELECT '330200205', '3302002'
GO
1>SELECT
2> (SELECT RIGHT('000' + CAST( COUNT(1) AS VARCHAR ), 3)
3> FROM #temp sub
4> WHERE
5> sub.Code2 = main.Code2
6> AND sub.Code1 <= main.Code1
7> ) AS 序号,
8> Code1 AS 代码1,
9> Code2 AS 代码2
10>FROM
11> #temp main
12>GO
序号 代码1代码2
------ ---------- -------
001330200101 3302001
002330200102 3302001
003330200103 3302001
004330200105 3302001
001330200201 3302002
002330200202 3302002
003330200203 3302002
004330200204 3302002
005330200205 3302002
(9 行受影响)
1、首先建一张测试表coal_blead,里面有多个字段。
2、输入“select * from coal_blead order by qnet,price”语句,按qnet,price字段进行升序排序。
3、输入“select * from coal_blead order by qnet desc,price desc”语句,先按qnet字段进行降序,再按price字段进行降序。
4、输入“select * from coal_blead order by qnet desc,price asc”语句,先按qnet字段降序,再按price字段进行升序。
5、如果想对更多的字段进行排序,可以进行添加。
你设计表的时候ID设置为自动增长型的就可以了,打开表就是按ID从小到大排列的。sql语句为:ID int IDENTITY (1, 1) primary key ,
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)