首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

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

2012-05-11 
sql语句或存储过程我表有3个字段:出现次数、手机号、基站码,我现在要把统计到某个手机号在哪一个基站出现次

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

热点排行