phone表:
key mobile create_time
a 123 2012-12-10
a 456 2012-12-11
b abc 2012-11-12
b def 2012-11-13
b ghi 2012-11-14查询key,key的数量,key最近的create_time,key最近create_time的mobile预计结果如下:
key count(key) 最近的mobile 最近的create_time
a 2 456 2012-12-11
b 3 ghi 2012-11-14想来半天,不知道SQL写,求指教!
key mobile create_time
a 123 2012-12-10
a 456 2012-12-11
b abc 2012-11-12
b def 2012-11-13
b ghi 2012-11-14查询key,key的数量,key最近的create_time,key最近create_time的mobile预计结果如下:
key count(key) 最近的mobile 最近的create_time
a 2 456 2012-12-11
b 3 ghi 2012-11-14想来半天,不知道SQL写,求指教!
解决方案 »
- oracle聚合函数中如何设置条件
- 如何从旧系统向新系统迁移数据(表结构变化很大)
- Oracle cpu 占用90%以上,系统缓慢
- 多个weblogic连接oracle,出现连接不稳定
- MFC ADO SQL delete语句执行进度问题,求教!
- SQL SERVER按时间 查询问题?
- 高手帮忙啊:insert date类型的数据
- 忘了某个用户的密码,我先把这个密码改掉,使用完毕然后改回来,但是出错....
- oracle 9i 会话问题2
- 不用客户端连接oralce数据库PLSQL10绿色版
- PLSQL中已经建表,怎样设置ID自动增长?
- 一个建立在View上的物化View 可以建立 on commit机制吗
from tableName a
left join (select key, count(*) num from tableName group by key) b on a.key =
b.key
right join (select key,max(createtime) createtime from tableName group by key) c on c.key=a.key and a.createtime=c.createtime
(
select key , count(key) , max(create_time) create_time from phone group by key
) a , phone b where a.create_time = b.create_time测试通过