给出表
id timeSpan
1 5天 10:00:00
2 20天 01:00:00
3 100天 01:00:00
根据timeSpan得到结果
id timeSpan
1 100天 01:00:00
2 20天 01:00:00
3 5天 10:00:00
还求一天sql语句解决此问题
SQL code:
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([id] int,[timeSpan] varchar(20))
insert [TB]
select 1,'5天 10:00:00' union all
select 2,'20天 01:00:00' union all
select 3,'100天 01:00:00'
select * from [TB] order by 2
/*
id timeSpan
----------- --------------------
3 100天 01:00:00
2 20天 01:00:00
1 5天 10:00:00
(所影响的行数为 3 行)
*/
drop table TB
SQL code:
order by
cast(left(timespan,patindex('%[吖-咗]%',timespan)-1) as int) desc,
right(timespan,8) desc
select * from [table] order by timeSpan desc
SQL code:
--默认的不是已经有一种排序了吗!
...........order by id desc
sorry !没看清!还是1楼的方法很好!
引用
相关问答:
执行的顺序: 1)文件浏览框(选择文件使用) 选择好文件后 点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下 2)读取这个文件夹下的csv的文件,转换成sql 3 ......
可能因为工作的原因 接触数据库这块比较少,之前都是做程序这块,数据库这块都有专门的人来做 分工都很明细 所以对数据库这一块完全不了解。前段时间 去面试了几家公司 几乎都是在数据库这块挂掉的 连个简单的SQ ......
从数据库中查询一张表的数据 select 部门,姓名 from tb 如何才能生成下面的xml格式 XML code: <folder state="unchecked" label="全部"> <folder state="unchecked&qu ......
请问 添加新数据源->数据库->添加连接 这个界面下,数据源选择:Microsoft SQL Server (SqlClient); 服务器名: 应该写什么呢? 有谁知道?多谢各位!! 你到底是要连mysql还是mssql? 引用 请问 ......
1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。 2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 ) 在系统属性设定里有个选项,可以修改单字段输出字数限制. ......