[一般难度]这样的句子怎么写?

fffddd 2003-08-01 11:11:25
一个表中有一日期型字段.如:
name birthday
--------- ------------
aaa 1981-11-2
bbb 1980-1-20
ccc 1981-10-30
eee 1987-2-2
....

怎么取出5位最近要过生日的人的名字?
...全文
85 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fffddd 2003-08-01
  • 打赏
  • 举报
回复
ACCEDSS中如何写呢?
tw_cshn 2003-08-01
  • 打赏
  • 举报
回复
oracle 数据库
select name,birthday from
(select t.name,t.birthday
from tw t where birthday is not null
order by
abs(to_number(to_char(birthday,'mm'))-to_number(to_char(sysdate,'mm'))),
abs(to_number(to_char(birthday,'dd'))-to_number(to_char(sysdate,'dd')))) a
where rownum<5
fffddd 2003-08-01
  • 打赏
  • 举报
回复
TO:myboor(菜菜菜鸟)
用户填写的生日都是今天以前(1980,1972..等等).这样写是不行的.
myboor 2003-08-01
  • 打赏
  • 举报
回复
不好选,我想既然是要过生日嘛,必然>今天,所以
select top 5 * from (select * from table where birthday>getdate() order by birthday)

俺可是测试过了,可以的
fffddd 2003-08-01
  • 打赏
  • 举报
回复
ACCESS好象没有(cast)这些函数吧.
firetoucher 2003-08-01
  • 打赏
  • 举报
回复
什么数据库?如果是sql server
select top 5 * from
(select name,cast( cast(year(getdate()) as char(4))+ '-' + cast(monthbirthday) as char(2))+'-'+cast( daybirthday) as char(2)) as datetime) as dd from table) a
where dd>getdate()
order by dd

其他的可以效仿

ps楼上的逻辑错误!
Microsoft OLE DB Provider for SQL Server 错误 '80040e31'

超时已过期

/Expert/reply.asp,行105
firetoucher 2003-08-01
  • 打赏
  • 举报
回复
什么数据库?如果是sql server
select top 5 * from
(select name,cast( cast(year(getdate()) as char(4))+ '-' + cast(monthbirthday) as char(2))+'-'+cast( daybirthday) as char(2)) as datetime) as dd from table) a
where dd>getdate()
order by dd

其他的可以效仿

ps楼上的逻辑错误!
esu 2003-08-01
  • 打赏
  • 举报
回复
改一下
select top 5 * from table where DATEPART(month, birthday)>=DATEPART(month, GETDATE()) and DATEPART(day, birthday)>=DATEPART(day, GETDATE()) order by DATEPART(month, birthday),DATEPART(day, birthday)
esu 2003-08-01
  • 打赏
  • 举报
回复
select top 5 * from table where DATEPART(month, birthday)=DATEPART(month, GETDATE()) and DATEPART(day, birthday)<=DATEPART(day, GETDATE())
gzllich 2003-08-01
  • 打赏
  • 举报
回复
select top 5 * from table where birthday>getdate() order by birthday

2,507

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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