查询当天记录 查询当天前10条记录,且当前不足10条时,也要显示10条记录SQL怎么写啊。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select top 10 * from tb where dt<getdate() order by dt desc select top 10 * from tb order by case when datediff(day,dt,gedate()) then 0 else 1 end, dt desc 呵呵.这是当天后十条...前十条:create table tb(dt datetime)insert into tb select '2010-12-17 16:23:20'insert into tb select '2010-12-17 17:23:20'insert into tb select '2010-12-17 18:23:20'insert into tb select '2010-12-17 19:23:20'insert into tb select '2010-12-17 20:23:20'insert into tb select '2010-12-17 21:23:20'insert into tb select '2010-12-17 22:23:20'insert into tb select '2010-12-17 23:23:20'insert into tb select '2010-12-18 03:23:20'insert into tb select '2010-12-18 05:23:20'insert into tb select '2010-12-18 07:23:20'insert into tb select '2010-12-18 09:23:20'goselect top 10 * from tborder by (case when left(dt,10)=left(getdate(),10) then datediff(ss,getdate(),dt) else datediff(ss,dt,getdate()) end)godrop table tb/*dt-----------------------2010-12-18 03:23:20.0002010-12-18 05:23:20.0002010-12-18 07:23:20.0002010-12-18 09:23:20.0002010-12-17 23:23:20.0002010-12-17 22:23:20.0002010-12-17 21:23:20.0002010-12-17 20:23:20.0002010-12-17 19:23:20.0002010-12-17 18:23:20.000(10 行受影响)*/ 存储过程的问题 从sql2000升级到sql2005,数据库连接写法有什么改变 给MySql的字符编码集设置为utf8后无法插入varchar类型的汉字,汉字允许输入10个,可是插入数据无法插上 不明白为什么??? 数据类型为什么修改不了 求教一个存储过程 数据库问题 关于比较两个表中的纪录的差异! 怎样在查询中把另外一个服务器连接起来??? 急!! 两台计算机的Sql Server70的数据库恢复? 机器码与注册码是一样多这是哪种算法 兄弟们帮着写条sql语句具体要求如下
前十条:
create table tb(dt datetime)
insert into tb select '2010-12-17 16:23:20'
insert into tb select '2010-12-17 17:23:20'
insert into tb select '2010-12-17 18:23:20'
insert into tb select '2010-12-17 19:23:20'
insert into tb select '2010-12-17 20:23:20'
insert into tb select '2010-12-17 21:23:20'
insert into tb select '2010-12-17 22:23:20'
insert into tb select '2010-12-17 23:23:20'
insert into tb select '2010-12-18 03:23:20'
insert into tb select '2010-12-18 05:23:20'
insert into tb select '2010-12-18 07:23:20'
insert into tb select '2010-12-18 09:23:20'
go
select top 10 * from tb
order by (case when left(dt,10)=left(getdate(),10) then datediff(ss,getdate(),dt) else datediff(ss,dt,getdate()) end)
go
drop table tb
/*
dt
-----------------------
2010-12-18 03:23:20.000
2010-12-18 05:23:20.000
2010-12-18 07:23:20.000
2010-12-18 09:23:20.000
2010-12-17 23:23:20.000
2010-12-17 22:23:20.000
2010-12-17 21:23:20.000
2010-12-17 20:23:20.000
2010-12-17 19:23:20.000
2010-12-17 18:23:20.000(10 行受影响)
*/