sql查询一年各个月最后一次记录

我有张表记录是按天统计的,我的查询条件是年比如说2009年,我要查2009年每月最后一天的记录,怎么查?请高手指教

select table_name.*
from table_name
where table_name.t_date in
(select max(t.t_date)
from table_name t
where to_char(t.t_date, 'yyyy') = '2009'
group by to_date(t.t_date, 'yyyy-mm'))

这是ORACLE的,未经过测试。
楼上写的是每个月最后一天的记录,不是每个月最后一条记录。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-01-15
For I = 1 TO 12
txtSQL = "Select * From 数据表名 Order BY 日期 Desc"
RS.Open txtSQL,1,2
IF DatePart("m",RS!日期) = I Then
'显示查询结果,根据你的需要设置,例如:
Text1(I - 1).Text = RS!日期
End If
RS.Close
Next I
第2个回答  2010-01-15
select * from
表 a
inner join
(
select month(天) 月,max(天) 天
from 表
where
year(天)=2009
group by
month(天)
) b
on
a.天 = b.天
第3个回答  2010-01-15
select month(date) 月,max(date) from biao where year(date)=2009 group by month(date)
相似回答