zoukankan      html  css  js  c++  java
  • 模拟or 改写union数据变多情形

    SQL> select * from test1;
    
       CUST_ID	FR_ID CI_BALANCE LN_BALANCE	MGR_ID
    ---------- ---------- ---------- ---------- ----------
    	10	   11	       0	  0	   100
    	10	   11	      12	 12	   101
    	10	   40	      12	 13	   101
    	10	   11	      12	 13	   100
    
    SQL> select * from test2;
    
       USER_ID
    ----------
           101
           102
           103
           100
    
    
    SQL>  select cust_id,fr_id,sum(ci_balance),sum(ln_balance) from test1
        where (mgr_id=100 or mgr_id in (select * from test2))
       group by  cust_id,fr_id  2    3  ;
    
       CUST_ID	FR_ID SUM(CI_BALANCE) SUM(LN_BALANCE)
    ---------- ---------- --------------- ---------------
    	10	   40		   12		   13
    	10	   11		   24		   25
    
    
    SQL> select cust_id,fr_id,sum(ci_balance),sum(ln_balance) from test1
    where (mgr_id=100)
    group by  cust_id,fr_id
    union
    select cust_id,fr_id,sum(ci_balance),sum(ln_balance) from test1
    where mgr_id in (select * from test2)
    group by  cust_id,fr_id  2    3    4    5    6    7  ;
    
       CUST_ID	FR_ID SUM(CI_BALANCE) SUM(LN_BALANCE)
    ---------- ---------- --------------- ---------------
    	10	   11		   12		   13
    	10	   11		   24		   25
    	10	   40		   12		   13
    
    
    
    
    
    
    SQL> select cust_id,fr_id,sum(ci_balance),sum(ln_balance) from test1
    where (mgr_id=100)
    group by  cust_id,fr_id  2    3  ;
    
       CUST_ID	FR_ID SUM(CI_BALANCE) SUM(LN_BALANCE)
    ---------- ---------- --------------- ---------------
    	10	   11		   12		   13
    
    SQL> select cust_id,fr_id,sum(ci_balance),sum(ln_balance) from test1
    where mgr_id in (select * from test2)
    group by  cust_id,fr_id  2    3  ;
    
       CUST_ID	FR_ID SUM(CI_BALANCE) SUM(LN_BALANCE)
    ---------- ---------- --------------- ---------------
    	10	   40		   12		   13
    	10	   11		   24		   25

  • 相关阅读:
    Promise对象
    iterator和for of 循环
    vue项目基本流程
    BASH_SOURCE 用法
    Java GC CMS 日志分析
    zookeeper 删除snapshot和transaction log的源码解读
    openresty nginx 安装过程记录
    opentesty--luasocket 安装
    为什么要使用SLF4J而不是Log4J
    要过一遍的博客列表
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352234.html
Copyright © 2011-2022 走看看