有以下几个表:
1.T_USER(系统用户表)
   OPERATOR_ID(用户编号)   NAME(用户姓名)   ORG_ID(用户所属班组编号)2.T_ROLE(系统角色表)
   ROLE_ID(角色编号  1组长  2组员)  ROLE_NAME(角色名称)3.T_USER_ROLE(用户角色表)
   OPERATOR_ID(用户编号)   ROLE_ID(角色编号)4.T_VALUE_USER(系统用户和客户对应表)
   MSISDN(客户手机号码)   OPERATOR_ID(用户编号)   H_GRADE(客户等级 1 钻  2 金  3 银)5.T_BOSS_BILI200908(客户7月份总费用表)
   MSISDN(客户手机号码)   TOTAL_FEE(总费用)6.T_BOSS_BILI200908(客户8月份总费用表)
   MSISDN(客户手机号码)   TOTAL_FEE(总费用)7.T_VOICE_CDR(客户通话记录)
   CALL_TIME(通话开始时间)   MSISDN(客户手机号码)   CALL_DURATION(通话时长-分钟)
问题:
        1.查询出班组编号为140001中各个用户对应的客户数;
        2.查询出与用户编号为1002用户同一班组的所有用户编号、姓名;
        3.查询出各个组长对应的三种等级的客户数(客户等级要求中文显示,结果按照用户编号、客户等级降序排列);
        4.查询出用户编号为1002的用户对应的客户7、8月份每月总费用(要求先用客户7、8月份的总费用表创建视图,再利用视图写出查询语句);
        5.查询出客户编号为1002的用户对应的客户8月份每人每天通话时长;
        6.写一个存储过程,将表T_USER_ROLE扩展一个字段NAME,类型为varchar2(48),并用游标,将T_USER的用户姓名更新到扩展的字段。

解决方案 »

  1.   

    1.
    select user.name,user.operator_id,count(distinct value.msisdn) from t_user user, t_value_user value where user.operator_id=value.operator_id and user.org_id=140001 group by user.operator_id;2.
    select user.operator_id,user.name from t_user user where user.org_id=(select distinct org_id from t_user where operator_id=1) group by user.operator_id
      

  2.   

    3.
    select * from t_user user, t_role role, t_user_role middle 
    where user.operator_id=middle.operator_id and middle.role_id=role.role_idselect user.operator_id,case when(value.h_grade=1) then '钻' when(value.h_grade=2) then '金' when(value.h_grade=3) then '银' end as grade, count(distinct value.msisdn)
    from t_user user,t_value_user value 
    where user.operator_id in(
    select distinct user.operator_id from t_user user, t_role role, t_user_role middle 
    where user.operator_id=middle.operator_id and middle.role_id=role.role_id and role.id=1) 
    and user.operator_id=value.operator_id group by user.operator_id,value.h_grade order by user.operator_id desc, value.h_grade desc;4
    CREATE
        VIEW `test`.`user_total_view` 
        AS
        (select user.operator_id, value.msisdn, boss7.total_fee as total7, boss8.total_fee as total8
    from t_user user,t_value_user value, t_boss_bili200907 boss7,t_boss_bili200908 boss8 
    where user.operator_id=value.operator_id and value.msisdn=boss7.msisdn and value.msisdn=boss8.msisdn group by(value.msisdn));select * from user_total_view where operator_id=1;
    上面sql语句都是对的,在我本地测试过的,包括上面1和2的sql也是运行通过的,都测试过
      

  3.   

    3.
    select * from t_user user, t_role role, t_user_role middle 
    where user.operator_id=middle.operator_id and middle.role_id=role.role_idselect user.operator_id,case when(value.h_grade=1) then '钻' when(value.h_grade=2) then '金' when(value.h_grade=3) then '银' end as grade, count(distinct value.msisdn)
    from t_user user,t_value_user value 
    where user.operator_id in(
    select distinct user.operator_id from t_user user, t_role role, t_user_role middle 
    where user.operator_id=middle.operator_id and middle.role_id=role.role_id and role.id=1) 
    and user.operator_id=value.operator_id group by user.operator_id,value.h_grade order by user.operator_id desc, value.h_grade desc;4
    CREATE
        VIEW `test`.`user_total_view` 
        AS
        (select user.operator_id, value.msisdn, boss7.total_fee as total7, boss8.total_fee as total8
    from t_user user,t_value_user value, t_boss_bili200907 boss7,t_boss_bili200908 boss8 
    where user.operator_id=value.operator_id and value.msisdn=boss7.msisdn and value.msisdn=boss8.msisdn group by(value.msisdn));select * from user_total_view where operator_id=1;
      

  4.   

    是否可以告诉我T_VOICE_CDR表的CALL_TIME字段类型 ,还有 CALL_DURATION字段类型,最好对每一个举个例子,我看看数据格式才可以弄