续 求出最近三天的日期。。。。。。。。

pengboy 2009-06-13 03:57:02
请问,我想求出最近三天的日期,
2009-6-12 16:47:15
2009-6-12 16:06:46
2009-6-12 12:45:13
2009-6-11 17:39:05
2009-6-9 19:27:47
2009-6-2 15:18:27

我想求出最近三天的日期

select top 3 addtime from info2 group by addtime order by addtime desc
这条语句把重复的日期也求出来了

之前是不带秒数的,现在是带上秒数,该怎么求,上面的语句不正确
...全文
32 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChinaJiaBing 2009-06-13
  • 打赏
  • 举报
回复

select * from @tb where addtime>=dateadd(dd,-3,getdate())


ChinaJiaBing 2009-06-13
  • 打赏
  • 举报
回复
请问,我想求出最近三天的日期,
2009-6-12 16:47:15
2009-6-12 16:06:46
2009-6-12 12:45:13
2009-6-11 17:39:05
2009-6-9 19:27:47
2009-6-2 15:18:27

我想求出最近三天的日期

select top 3 addtime from info2 group by addtime order by addtime desc
这条语句把重复的日期也求出来了

select * from @tb where addtime>dateadd(dd,-3,getdate())
penfriends 2009-06-13
  • 打赏
  • 举报
回复
addtime +3天 和当前系统时间比较
ai_li7758521 2009-06-13
  • 打赏
  • 举报
回复
select top 3 date
from (SELECT date=convert(char(10),date,120) from @TB) A
group by date
order by date desc

date
----------
2008-08-04
2008-08-03
2008-08-02

(3 行受影响)
ai_li7758521 2009-06-13
  • 打赏
  • 举报
回复
DECLARE @TB table(date smalldatetime)
insert @TB
SELECT '2008-8-3 16:47:15 ' union all
SELECT '2008-8-1 16:06:46 ' union all
SELECT '2008-8-2 12:45:13 ' union all
SELECT '2008-8-1 17:39:05 ' union all
SELECT '2008-8-3 17:39:06 ' union all
SELECT '2008-8-2 17:39:35 ' union all
SELECT '2008-8-1 17:39:25 ' union all
SELECT '2008-8-4 17:39:15 '


select top 3 date
from @TB
group by date
order by date desc

date
-----------------------
2008-08-04 17:39:00
2008-08-03 17:39:00
2008-08-03 16:47:00

(3 行受影响)
ai_li7758521 2009-06-13
  • 打赏
  • 举报
回复
DECLARE @TB table(date smalldatetime)
insert @TB
SELECT '2008-8-3' union all
SELECT '2008-8-1' union all
SELECT '2008-8-2' union all
SELECT '2008-8-1' union all
SELECT '2008-8-3' union all
SELECT '2008-8-2' union all
SELECT '2008-8-1' union all
SELECT '2008-8-4'


select top 3 date
from @TB
group by date
order by date desc

date
-----------------------
2008-08-04 00:00:00
2008-08-03 00:00:00
2008-08-02 00:00:00

(3 行受影响)
pengboy 2009-06-13
  • 打赏
  • 举报
回复
我 数据库用的ACCESS
--小F-- 2009-06-13
  • 打赏
  • 举报
回复
----------------------------------------------------------------
-- Author :fredrickhu(小F 向高手学习)
-- Date :2009-06-13 16:05:00
----------------------------------------------------------------
--> 测试数据:@info2
declare @info2 table([addtime] datetime)
insert @info2
select '2008-8-3' union all
select '2008-8-1' union all
select '2008-8-2' union all
select '2008-8-1' union all
select '2008-8-3' union all
select '2008-8-2' union all
select '2008-8-1' union all
select '2008-8-4'
--------------开始查询--------------------------

SELECT TOP 3 convert(char(10),addtime,120) addtime FROM (SELECT DISTINCT * FROM @info2)AS T ORDER BY addtime DESC


----------------结果----------------------------
/*addtime
2008-08-04
2008-08-03
2008-08-02


*/

风_雨_晴 2009-06-13
  • 打赏
  • 举报
回复
select top 3 convert(varchar, addtime, 102)
from info2
group by convert(varchar, addtime, 102)
order by convert(varchar, addtime, 102) desc
-狙击手- 2009-06-13
  • 打赏
  • 举报
回复
select top 3 convert(char(10),addtime,120)
from info2
group by convert(char(10),addtime,120)
order by addtime desc
sysuzzj 2009-06-13
  • 打赏
  • 举报
回复
up

22,298

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧