查询编号为0099日期最大的最后一条记录
编号 日期 字段1 字段2 ...
1000 2007-01-01 1 a ...
0099 2007-02-03 2 b ...
1000 2007-02-08 2 c ...
1001 2007-02-02 0 c ...
0099 2007-03-18 0 l ...
... ... . . ... 得到:
编号 日期 字段1 字段2 ...
0099 2007-03-18 0 l ...
编号 日期 字段1 字段2 ...
1000 2007-01-01 1 a ...
0099 2007-02-03 2 b ...
1000 2007-02-08 2 c ...
1001 2007-02-02 0 c ...
0099 2007-03-18 0 l ...
... ... . . ... 得到:
编号 日期 字段1 字段2 ...
0099 2007-03-18 0 l ...
解决方案 »
- 通过LinkServer插入数据问题
- 对于 join, 如果不写 left ,inner ,right ,默认是什么联接呢?
- 如何优化这条SQL语句?
- 求2个SQL语句
- 求助SQL语句:增加一个字段到特定的位置!
- 如何运行sql scripts
- 十几万条记录,对数据库操作时CPU很高????
- 请教一个循环生成记录的方法
- SQL Transaction 问题求教高手?
- 怎樣遍歷一個表中的記錄?
- 刚insert一条记录到数据库,如何取它的id和某个字段值?
- 烦劳帮助,在线待回答,谢谢[microsoft][0dbc sql sever driver][shared memory]sql server 不存在或访问被
select top 1 * from tb where 编号='0099' order by 日期 desc
where not exists(select 1 from tb where t.编号=编号 and t.日期<日期)
select top 1 * from tb t where 编号 = '0099' order by 日期 desc--如果是所有编号
select t.* from tb t where 日期 = (select max(日期) from tb where 编号 = t.编号)
select t.* from tb t where not exists (select 1 from tb where 编号 = t.编号 and 日期 > t.日期)