描述一下需求:就是查找用户访问最多的城市
字段 imei , cityid , cnt (分别表示,用户ID,城市ID,访问次数)举例 1234 0001 33
1234 0002 32
1222 0001 20
1222 0003 22显示结果1234 0001 33
1222 0003 22这句SQL怎么写啊 谢啦
Oracle 10G
字段 imei , cityid , cnt (分别表示,用户ID,城市ID,访问次数)举例 1234 0001 33
1234 0002 32
1222 0001 20
1222 0003 22显示结果1234 0001 33
1222 0003 22这句SQL怎么写啊 谢啦
Oracle 10G
解决方案 »
- 查询出所有在1981年被雇佣的员工信息
- 求个统计的sql(内详)
- 急急急TT~菜鸟求助
- 如何读取存储过程本身的代码内容
- 使用Database Configuration Assistant使用General Purpose模板,里面的关于默认配置是自动产生还是每次都相同?
- 用dblink取存储过程返回游标时报 ORA-24338: 未执行语句句柄
- 急!cursor结果集值改变,并返回结果集。在线等,很难,高手进,答出来立即给分。
- 执行sql语句,半天没有反应,怎么回事?
- 怎以查看当前库的表空间总量是多少,用了多少,还剩多少?
- oracle如何得到用户创建的表名
- 请教,听说oracle官方网站有一个很大的资料库可以下载,但是我找半天也没找到,知道的高手给个链接啊! 谢谢~
- 什么意思
group by imei;
where cnt=(select max(cnt) from T1 b where a.imei=b.imei and a.cityid=b.cityid)
group by imei,cityid ;
with tt as
(
select '1234' imei, '0001' cityid, '33' cnt from dual
union all
select '1234','0002','32' from dual
union all
select '1222','0001','20' from dual
union all
select '1222','0003','22' from dual
)
select imei,cityid,cnt from tt where (imei,cnt) in (
select imei,max(cnt)over(partition by imei) from tt );
这是代码,tt是测试数据,换成表就可以了.select imei,cityid,cnt from tt where (imei,cnt) in (
select imei,max(cnt)over(partition by imei) from tt );
------------------------------------------------------------------------------
Blog: http://blog.csdn.net/tianlesoftware
网上资源: http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
Q Q 群:62697716
更具体一些imei cityid mnc cnt
1234 0001 01 33
1234 0001 02 34
1234 0002 01 35
1234 0002 02 33
就只要显示 1234 0002 (cnt=35)这个结果
你这个结果会是1234 0002 35 | 1234 0001 34
from test a, (select id, max(time) time from test group by id) b
where a.id = b.id
and a.time = b.time
或
select *
from test a
where exists (select 1
from (select id, max(time) time from test group by id) b
where a.id = b.id
and a.time = b.time)