码迷,mamicode.com
首页 > 其他好文 > 详细

创建视图

时间:2015-04-30 10:33:21      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

 

CREATE VIEW v_total_asset
    (cid,fin,wallet)
AS 
SELECT c.cid,nvl((
    SELECT SUM(f.total_num*nvl(
                        CASE 
                           WHEN f.prof_mod=1 THEN 1
                           WHEN f.prof_mod=0 THEN f.prod_net
                           ELSE 1
                        END
                    ,1)) FROM t_fin_held f WHERE f.cid = c.cid 
 ),0) AS fin,nvl((
    SELECT SUM(w.total_amt) FROM t_wallet_balance w WHERE w.cid = c.cid AND w.fund_state = 0
),0) AS wallet
     FROM  t_customer cc
     


CREATE VIEW v_mgr_cust_asset
    (id,mgr_id,cid,cust_name,risk_level,birthday,phone_number,mark_prop,priority,check_status,mc_desc,fin,wallet,total_asset)
AS 
SELECT m.id,m.mgr_id,m.cid,c.cust_name,c.risk_level,c.birthday,c.phone_number,m.mark_prop,nvl(m.priority,0) AS priority,m.check_status,m.mc_desc,a.fin,a.wallet,(a.fin+a.wallet) AS total_asset
 FROM t_mgr_cust m 
    LEFT JOIN v_total_asset a ON a.cid = m.cid
    LEFT JOIN t_customer c ON c.cid = m.cid

 

创建视图

标签:

原文地址:http://www.cnblogs.com/mingforyou/p/4468139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!