请教asp中sql查询的问题,100分送上

97jr 2003-10-16 04:29:45
我想查询一个表中日期字段(格式为:1999-12-31)的值中年份最大的那个字段,请问sql语句该怎么写?
比如:这个字段中有如下记录
2001-05-06
2002-05-08
2002-09-04
2003-07-08
2003-06-04
我要查出年份为2003的记录,不知道怎么写语句。
...全文
22 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
dafei0320 2003-10-21
  • 打赏
  • 举报
回复
select max(time) from table
就行了啊!
gmlxf 2003-10-20
  • 打赏
  • 举报
回复
其实楼上的很多都是对的,不知道楼主要查询出什么样的?
select * from 表名 where year(日期字段名)=(select max(year(日期字段名)) from 表名)
or
select * from 表名 where year(日期字段名) in (select max(year(日期字段名)) from 表名)
在sql server都通过。不知道楼主是什么数据库。
61 2003-10-16
  • 打赏
  • 举报
回复
select * from tablename where year(DateTime)=2003
tigerwen01 2003-10-16
  • 打赏
  • 举报
回复
这是最完美的算法:
select * from table where year(日期类型字段) in (select max(year(日期类型字段)) from table)
-----------------------------------
我在SQL SERVER2000的SQL查询分析器里测试通过以下语句:
select * from sales where year(ord_date) in (select max(year(ord_date)) from sales)
97jr 2003-10-16
  • 打赏
  • 举报
回复
这样写都不行的
tigerwen01 2003-10-16
  • 打赏
  • 举报
回复
给你一个完整的解决方案:
select maxyear=max(year(日期类型字段)) from table
Dim MaxYear
MaxYear=rs("maxyear")
select * from table where year(日期类型字段)='"&MaxYear&"'
qdubit 2003-10-16
  • 打赏
  • 举报
回复
select * from 表名 where year(日期字段名)=(select max(year(日期字段名)) from 表名)
这样肯定正确,我已经验证了!
yzxlyd 2003-10-16
  • 打赏
  • 举报
回复
哇,好多呀。有得学了。
happymingnan 2003-10-16
  • 打赏
  • 举报
回复
select * from 表 where year(time_zd)=2003
接分
sunnylake 2003-10-16
  • 打赏
  • 举报
回复
select * from table where year(time_zd)=2003
tigerwen01 2003-10-16
  • 打赏
  • 举报
回复
select max(year(日期类型字段)) from table
zrla 2003-10-16
  • 打赏
  • 举报
回复
select max(year(日期字段)) from 表
详细操作你可以看看sql帮助中的select语句那里涵盖了所有的情况
包括字句设置等内容!
herman_chow 2003-10-16
  • 打赏
  • 举报
回复

select * from tb where convert(char(4),日期字段,120)='2003'
sunnylake 2003-10-16
  • 打赏
  • 举报
回复
sorry 日期型不可以用left()
还是oozeking对
sunnylake 2003-10-16
  • 打赏
  • 举报
回复
select * from table where left(time,4)=2003
oozeking 2003-10-16
  • 打赏
  • 举报
回复
select * from tb where year(日期字段)=(select max(year(time)) from table
)
bflovesnow 2003-10-16
  • 打赏
  • 举报
回复
select max(year(日期字段)) from tb
pp4u 2003-10-16
  • 打赏
  • 举报
回复
select max(year(time)) from table
bflovesnow 2003-10-16
  • 打赏
  • 举报
回复
select * from tb where year(日期字段)=2003
pp4u 2003-10-16
  • 打赏
  • 举报
回复
select max(time) from table

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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