如下表:tab 中有如下记录(cid是栏目分类) ID CID title times
1 2 aaa 2009-01-19 21:08:22
2 2 aaa 2009-01-18 01:04:32
3 3 a4a 2009-01-19 21:08:52
4 3 cca 2009-01-17 11:08:13
5 3 aay 2009-01-19 21:08:22
6 2 bbb 2009-01-16 11:28:25
7 2 vva 2010-09-19 56:35:11
8 1 78a 2010-01-18 16:21:33
9 1 lkd 2009-01-19 21:08:22我目前的SQL语句:
SELECT id,cid,max(times) as dtimes,title FROM tab group by cid order by dtimes desc这个SQL语句虽然过滤掉了重复记录信息,显示的结果里,时间一项也显示的是最新时间记录,但是title显示的信息,确是最早添加的信息,请问如何,显示最新的title信息呢?
1 2 aaa 2009-01-19 21:08:22
2 2 aaa 2009-01-18 01:04:32
3 3 a4a 2009-01-19 21:08:52
4 3 cca 2009-01-17 11:08:13
5 3 aay 2009-01-19 21:08:22
6 2 bbb 2009-01-16 11:28:25
7 2 vva 2010-09-19 56:35:11
8 1 78a 2010-01-18 16:21:33
9 1 lkd 2009-01-19 21:08:22我目前的SQL语句:
SELECT id,cid,max(times) as dtimes,title FROM tab group by cid order by dtimes desc这个SQL语句虽然过滤掉了重复记录信息,显示的结果里,时间一项也显示的是最新时间记录,但是title显示的信息,确是最早添加的信息,请问如何,显示最新的title信息呢?
解决方案 »
- 我用mysql创建的存储过程有错误,大家帮我看一下
- mysql存储过程中动态构造sql语句
- 用jdbc从mysql取blob老是没有办法还原成图片,怎么回事
- 朋友的一个问题,我没有解决掉,汗,请高手相助。
- 急,如何获取表中主键的确名称?Sybase和SQL的语句各改怎么写?
- WindowsMySQL问题:怎样在已建表中插入新的一列?
- 帮帮我啊,本是小问题,对我却是大问题(resin3.0语mysql3.23的驱动jdbc怎么连接)
- 添加用户(菜鸟级),帮帮忙!
- mysql 无法启动.查阅几个小时资料无法解决.前辈们进来看看
- 谁能告诉我这是怎么回事啊?
- 网站报错大家帮忙看下
- MySQL创建function时出错
from tab a
where not exists (select 1 from tab where cid=a.cid and times>a.times)
where
not exists
(
select 1 from tab where cid=a.cid and times>a.times
)
(SELECT cid,max(times) as dtimes,title FROM tab group by cid order by dtimes desc) b
on a.cid=b.cid and a.times=b.dtimes
(select cid,max(times) as mt from tab group by cid) t2
on t1.cid=t2.cid and t1.times=t2.mt
order by t1.times desc
sELECT max(time) from table t where t.cid=table.cid group by cid);
on a.cid=b.cid and a.times=b.times;