有这样的SQL语句:
- SQL code
SELECT A.patient_id,A.RCPT_NO,sum(C.costs) s_xj,sum(decode(C.class_on_rcpt,'A',C.costs,0)) s_xyf,sum(decode(C.class_on_rcpt,'B',C.costs,0))+sum(decode(C.class_on_rcpt,'F',C.costs,0)) s_zyf,sum(decode(C.class_on_rcpt,'I',C.costs,0))+sum(decode(C.class_on_rcpt,'E',C.costs,0))+sum(decode(C.class_on_rcpt,'C',C.costs,0)) s_ybjc,sum(decode(C.class_on_rcpt,'D',C.costs,0))+sum(decode(C.class_on_rcpt,'H',C.costs,0))+sum(decode(C.class_on_rcpt,'G',C.costs,0)) s_ybzl,(select sum(c.costs) from from outp_rcpt_master A,outp_bill_items C WHERE A.charge_type LIKE '%费%' and A.rcpt_no=C.rcpt_no and (C.class_on_rcpt='C' OR C.class_on_rcpt='E' OR C.class_on_rcpt='I')) s_tsjc,'' s_tZ,sum(decode(C.class_on_rcpt,'J',C.costs,0)) s_qt,sum(C.charges) s_zfxj,'' s_zfbl,'' s_zftj,'' s_zftz,sum(decode(C.class_on_rcpt,'J',C.charges,0)) s_zfqt,sum(C.costs) - sum(C.charges) s_jsffrom outp_rcpt_master A,outp_bill_items CWHERE A.charge_type LIKE '%费%'and A.visit_date>=to_date('2010-01-01','yyyy-mm-dd')and A.visit_date<to_date('2011-01-01','yyyy-mm-dd')and A.rcpt_no=C.rcpt_nogroup by A.patient_id,A.RCPT_NO;
现在的问题在于
(select sum(c.costs) from from outp_rcpt_master A,outp_bill_items C WHERE A.charge_type LIKE '%费%' and A.rcpt_no=C.rcpt_no and (C.class_on_rcpt='C' OR C.class_on_rcpt='E' OR C.class_on_rcpt='I')) s_tsjc
s_tsjc---这里,小弟实在不知道如何才能求出每个人的s_tsjc!!!
麻烦哪位高手给琢磨琢磨(上面的SQL语句还没有优化过),谢谢。
------解决方案--------------------
把表结构,和样本数据列出来,再说明要得到的结果,要好些。
------解决方案--------------------
select sum(c.costs) from from outp_rcpt_master A,outp_bill_items C ?
不明白你的意思
1、是否多了from?
2、能否可以用unoin之类的
------解决方案--------------------