mysql查询难题,高手看看
id cid content datetime
1 1 aaaa 1306314239
2 1 aaaa 1306314129
3 2 aaaa 1306314243
4 2 aaaa 1306314342
5 2 aaaa 1306314253
要求
1:查询cid = 1 和cid = 2 中时间最大的一条?
2:查询datatime 时间少 一天 or 一小时的条数?
1 1 aaaa 1306314239
2 1 aaaa 1306314129
3 2 aaaa 1306314243
4 2 aaaa 1306314342
5 2 aaaa 1306314253
要求
1:查询cid = 1 和cid = 2 中时间最大的一条?
2:查询datatime 时间少 一天 or 一小时的条数?
作者: flyingcloud_zyf 发布时间: 2011-05-26
SQL code
select * from tbname where cid in(1,2) order by FROM_UNIXTIME(datetime) desc limit 1;
作者: zuoxingyu 发布时间: 2011-05-26
1:查询cid = 1 和cid = 2 中时间最大的一条?
SQL code
2:查询datatime 时间少 一天 or 一小时的条数?
SQL code
SQL code
select * from table1 where cid = 1 or cid = 2 order by datetime desc limit 1;
2:查询datatime 时间少 一天 or 一小时的条数?
SQL code
select * from table1 order by datatime limit 1
作者: ACMAIN_CHM 发布时间: 2011-05-26
不是十分看懂第二个问题。猜着看吧。
(不要高估你的汉语表达能力或者我的汉语理解能力)
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
(不要高估你的汉语表达能力或者我的汉语理解能力)
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
作者: ACMAIN_CHM 发布时间: 2011-05-26
1
select *
from tb A
where not exists (select 1 from tb A.cid=cid and A.cid<cid)
select *
from tb A
where not exists (select 1 from tb A.cid=cid and A.cid<cid)
作者: rucypli 发布时间: 2011-05-26
顶一下,看结果,不明白第二个问题
作者: taocaoren10000 发布时间: 2011-05-26