select * from table where id='001' order by timeif (rs.next()) {
第一条记录就是最新的
}
第一条记录就是最新的
}
解决方案 »
- weblogic中的编码问题
- 在web.xml中配置<welcome-file-list>控制页面跳转的问题
- 请教:hibernate3连不上SQL server
- 如何action中得到jsp页面<select>标签中是值
- hibernate criteria关联筛选查询怎么写?
- 请教高手:如何进行搜索链接?(使用jsp)
- 这是我写的一个mail发送组件,有错误,那位大哥帮我调调,很急,搞定就给分
- 使用jspsmartupload组件,系统抛出Error异常!!!
- 各位高手,救急啊~~~~~~~~~
- 这里难道没有高手?这个问题没有人能回答吗?100分悬赏!!!
- Tomcat下,中文字符显示乱码的问题。
- 求救!!关于jni本地方法調用的問題,我用javah生成h文件,為甚麼編譯不成?(說(*env)->GetStringUTFChars(...)沒有->操作符)為甚麼?
第一条数据就是最新记录
它会把刚输入的数据,也就是最新记录,自动做为第一条显示出来。
表table1
id time content
001 2003-07-10 第一条
002 2003-07-11 一条
001 2003-08-01 第二条
002 2003-08-09 一条
001 2003-08-11 最后一条
表table2
id time detail bak
003 2003-07-10 第一条 haha
004 2003-07-11 一条 haha
003 2003-08-01 第二条 haha
004 2003-08-09 一条 haha
003 2003-08-11 最后一条 haha我现在想取出不同id的最后一条记录
得出的结果如下
001 2003-08-11 最后一条
002 2003-08-09 一条
003 2003-08-11 最后一条
004 2003-08-09 一条请高手再指教一下,一定给分!以上兄弟我也会给分的,多些!请注意表的有些字段是不同的
select top 1 id,time,content
from table1 where id in
(select distinct id from table1)
order by time desc
union
select top 1 id,time,content
from table1 where id in
(select distinct id from table1)
order by time desc
union
select top 1 id,time,detail as content
from table2 where id in
(select distinct id from table1)
order by time desc
union
select top 1 id,time,detail as content
from table2 where id in
(select distinct id from table1)
order by time desc
from table1 where id ='001'
order by time desc
union
select top 1 id,time,content
from table1 where id ='002'
order by time desc
union
select top 1 id,time,detail as content
from table2 where id ='003'
order by time desc
union
select top 1 id,time,detail as content
from table2 where id ='004'
order by time desc
还是写存储过程吧
似乎sql扛不住
想多给大家点分,可系统不允许,只好对不起大家了!
select * from table A ,(select id,max(time) from table group by id) B where A.id=B.id and A.time=B.time
其实主要的创意还是楼上的
这个问题也得到了完美的解决
select id,time,content
from table1 A ,(select id,max(time) from table1 group by id) B
where A.id=B.id and A.time=B.time
union
select id,time,detail as content
from table2 C ,(select id,max(time) from table2 group by id) D
where C.id=D.id and C.time=D.time