比如说有5条记录
id content
========================
1 举例内容
2 abc
3 A
4 举例内容123
5 1234
我希望按照 content 数据内容的长度 len() 来升序排列,得出3,2,5,1,4的排列结果,请问如何写 order by ? 谢谢了!
id content
========================
1 举例内容
2 abc
3 A
4 举例内容123
5 1234
我希望按照 content 数据内容的长度 len() 来升序排列,得出3,2,5,1,4的排列结果,请问如何写 order by ? 谢谢了!
from tb
order by len(content)
-- Author: HEROWANG(让你望见影子的墙)
-- Date : 2009-09-09 22:50:40
---------------------------------
IF OBJECT_ID('[tb]') IS NOT NULL
DROP TABLE [tb]
go
CREATE TABLE [tb] (id INT,content VARCHAR(11))
INSERT INTO [tb]
SELECT 1,'举例内容' UNION ALL
SELECT 2,'abc' UNION ALL
SELECT 3,'A' UNION ALL
SELECT 4,'举例内容123' UNION ALL
SELECT 5,'1234'select * from [tb]
order by datalength(content)id content
3 A
2 abc
5 1234
1 举例内容
4 举例内容123
select * from 表
order by len(content)
select * from 表
order by datalength(content)
返回任何表达式所占用的字节数。语法
DATALENGTH ( expression ) 参数
expression任何类型的表达式。返回类型
intcode]