当前位置: 代码迷 >> Oracle面试 >> sql语句或存储过程解决方法
  详细解决方案

sql语句或存储过程解决方法

热度:3444   发布时间:2013-02-26 00:00:00.0
sql语句或存储过程
我表有3个字段:出现次数、手机号、基站码,我现在要把统计到某个手机号在哪一个基站出现次数最大的基站码填到另外一个表的对应手机号的字段中,应该共有100多个手机号,所以想写个存储过程,但是一直没成功,想请教大侠帮忙!

oracle 或者有其他方式也行,谢谢,穷啊 分有点少 帮个忙 呵呵

------解决方案--------------------------------------------------------
with MaxCnt as 
(select mobile,cgi_num,count(*) cnt 
 from manager_log 
 group by mobile,cgi_num),
cgi as
(select mobile,max(cnt) cnt from MaxCnt group by mobile),
cgi1 as
(select MaxCnt.mobile,MaxCnt.cgi_num from MaxCnt,cgi where cgi.mobile = MaxCnt.mobile and cgi.cnt = MaxCnt.cnt)

update (
select cgi1.mobile as mob1,cgi1.cgi_num,
cgi_manager.mobile as mob2,cgi_manager.cgi
from cgi1,cgi_manager 
where cgi1.mobile = cgi_manager.mobile)
set cgi = cgi_num
  相关解决方案