给出表
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楼的方法很好!
引用
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle) 现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
id url rank ......