日期:2014-05-18 浏览次数:20463 次
select a.acc_nbr,a.serv_id,sum(i.charge/100), (select m.TYPE_NAME from 表m where m.type_code = a.std_tml_id and m.merge_group_id = 6)县名 from 表a,表 i where i.serv_id=a.serv_id group by a.acc_nbr,a.serv_id
------解决方案--------------------
select a.acc_nbr,a.serv_id,sum(i.charge/100), (select m.TYPE_NAME from 表m where m.type_code = a.std_tml_id and m.merge_group_id = 6)县名 from 表a,表 i where i.serv_id=a.serv_id group by a.acc_nbr,a.serv_id --这样就行吧
------解决方案--------------------
--试试 select a.acc_nbr , a.serv_id , sum(i.charge / 100) , max(( select m.type_name from 表m where m.type_code = a.std_tml_id and m.merge_group_id = 6 )) 县名 from 表a , 表 i where i.serv_id = a.serv_id group by a.acc_nbr , a.serv_id
------解决方案--------------------
select a.acc_nbr,a.serv_id,sum(i.charge/100),m.TYPE_NAME from 表a a join 表i i on i.serv_id=a.serv_id left join 表m m on m.type_code = a.std_tml_id and m.merge_group_id = 6 group by a.acc_nbr,a.serv_id,m.TYPE_NAME
------解决方案--------------------
select a.acc_nbr,a.serv_id,sum(i.charge/100),m.TYPE_NAME
from 表a a join 表i i on i.serv_id=a.serv_id
left join 表m m on m.type_code = a.std_tml_id and m.merge_group_id = 6
group by a.acc_nbr,a.serv_id,m.TYPE_NAME
这个比较合理
------解决方案--------------------
把子查询用关联来做 就好点 而且数据量大速度也会快点