CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Oracle >  开发

请教group by!

楼主delian(仲秋)2003-09-01 23:47:48 在 Oracle / 开发 提问

table1  
  name         sl  
  ----         ---  
  aaa           3  
  bbb           2  
  ccc           5  
  aaa           2  
  fff           7  
  bbb           1  
   
  table2:  
  name         sl  
  -----     ----  
  aaa           1  
  fff           6  
   
  怎样得出这样的结果:  
   
  name         sl_1         sl_2     sl3  
  -----       ----         ----     ----  
  aaa             5               1           4  
  bbb             3               0           0  
  ccc             5               0           0  
  fff             7               6           1  
   
  先谢了!  
  问题点数:0、回复次数:8Top

1 楼delian(仲秋)回复于 2003-09-02 00:12:07 得分 0

写错了,更改为:  
     
         
  table1      
  name                 sl      
  ----                 ---      
  aaa                     3      
  bbb                     2      
  ccc                     5      
  aaa                     2      
  fff                     7      
  bbb                     1      
     
  table2:      
  name                 sl      
  -----             ----      
  aaa                     1      
  fff                     6      
  aaa                     1  
     
  怎样得出这样的结果:      
     
  name                 sl_1                           sl_2               sl3      
  -----             ----                               ----           ----      
  aaa                         5                             2                     3      
  bbb                         3                             0                     3      
  ccc                         5                             0                     5      
  fff                         7                             6                     1      
     
     
  Top

2 楼delian(仲秋)回复于 2003-09-02 00:13:05 得分 0

写错了,更改为:  
     
  table1      
  name                 sl      
  ----                 ---      
  aaa                     3      
  bbb                     2      
  ccc                     5      
  aaa                     2      
  fff                     7      
  bbb                     1      
     
  table2:      
  name                 sl      
  -----             ----      
  aaa                     1      
  fff                     6      
  aaa                     1  
     
  怎样得出这样的结果:      
     
  name                 sl_1                           sl_2               sl3      
  -----             ----                               ----           ----      
  aaa                         5                             2                     3      
  bbb                         3                             0                     3      
  ccc                         5                             0                     5      
  fff                         7                             6                     1      
     
     
  Top

3 楼beckhambobo(beckham)回复于 2003-09-02 09:36:26 得分 0

select   name,s1_1,s1_2,(s1_1-s1_2)   sl3   from    
  (select   name,sum(s1)   s1_1,(select   sum(s1)   from   table2   where   name=table1.name)   sl_2   from   table1   group   by   name)Top

4 楼delian(仲秋)回复于 2003-09-02 11:54:15 得分 0

to:   beckhambobo(beckham)    
  我实际的两张表是这样的:  
  A表数据:  
  品牌           型号           规格           数量           单价             合计  
  10001 10003 100010 3 11300 33900  
  10001 10003 100010 1 11200 11200  
  10007 10019 100042 1 1 1  
  10007 10023 100046 11 23 253  
  10001 10003 100018 2 10200 20400  
  10001 10003 100027 4 11500 46000  
   
  B表数据  
  品牌           型号           规格           数量           单价             合计  
  10001 10003 100010 1 12000 12000  
  10001 10003 100010 1 12500 12500  
  10001 10003 100010 1 12000 12000  
  10007 10019 100042 1 3 3  
  10007 10023 100046 2 30 60  
   
  要得出的结果是:  
  品牌           型号           规格           A数量         B数量       库存数量(A数量   -   B数量)  
  10001 10003 100010 4 3 1  
  10001 10003 100018 2                   0               2Top

5 楼beckhambobo(beckham)回复于 2003-09-02 12:18:41 得分 0

select   品牌,型号,规格,s1_1,s1_2,(s1_1-s1_2)   sl3   from    
  (select   品牌,型号,规格,sum(数量)   s1_1,(select   sum(数量)   from   table2   where   品牌=table1.品牌   and   型号=table1.型号   and   规格=table1.规格)   sl_2   from   table1   group   by   品牌,型号,规格)  
  Top

6 楼delian(仲秋)回复于 2003-09-02 13:13:30 得分 0

TO:   beckhambobo(beckham)  
  这样写报错:  
  select     cpmc,ppmc,xhmc,s1_1,s1_2,(s1_1-s1_2)   sl3   from    
  (select   cpmc,ppmc,xhmc,sum(rksl)   s1_1,(select   sum(cksl)   from   v_kc_ckbb01   where    
                cpmc=v_kc_rkbb01.cpmc   and   ppmc=v_kc_rkbb01.ppmc   and   xhmc=v_kc_rkbb01.xhmc)   sl_2    
      from   v_kc_rkbb01   group   by   cpmc,ppmc,xhmc);  
   
  执行后;  
   
  连接到:  
  Oracle8   Enterprise   Edition   Release   8.0.5.0.0   -   Production  
  PL/SQL   Release   8.0.5.0.0   -   Production  
   
  SQL>   select     cpmc,ppmc,xhmc,s1_1,s1_2,(s1_1-s1_2)   sl3   from    
      2     (select   cpmc,ppmc,xhmc,sum(rksl)   s1_1,(select   sum(cksl)   from   v_kc_ckbb01   where    
      3                   cpmc=v_kc_rkbb01.cpmc   and   ppmc=v_kc_rkbb01.ppmc   and   xhmc=v_kc_rkbb01.xhmc)   sl_2    
      4         from   v_kc_rkbb01   group   by   cpmc,ppmc,xhmc);  
  (select   cpmc,ppmc,xhmc,sum(rksl)   s1_1,(select   sum(cksl)   from   v_kc_ckbb01   where  
                                                                                *  
  错误位于第2行:  
  ORA-00936:   缺少表达式  
   
  Top

7 楼beckhambobo(beckham)回复于 2003-09-02 14:36:26 得分 0

select   品牌,型号,规格,s1_1,s1_2,(s1_1-s1_2)   sl3   from    
  (select   品牌,型号,规格,sum(a.数量)   s1_1,sum(b.数量)   sl_2   from   table1   a,table2   b   where   a.品牌=b.品牌(+)   and   a.型号=b.型号(+)   and   a.规格=b.规格(+)   group   by   品牌,型号,规格)  
  Top

8 楼zbhtj(钢骨黑布伞)回复于 2003-09-03 14:49:31 得分 0

select     a.name,s1_1,nvl(s1_2,0)   ,   (s1_1-nvl(s1_2,0))   s3  
  from  
  (select     name,sum(s1)   s1_1  
  from   aaa  
  group   by   name)     a,  
  (select   a1.name,sum(bbb.s1)   s1_2      
  from   bbb,(select   distinct   name     from   aaa   )   a1  
  where   a1.name=bbb.name(+)  
  group   by   a1.name)     b  
  where   a.name=b.nameTop

相关问题

  • Group by
  • group by and distinct
  • 关于group by
  • group by 的问题
  • 关与GROUP BY !
  • group by 问题
  • distinct与group by?
  • group by的问题
  • select , count ,group by ????
  • google group? (100分!!!)

关键词

  • sl
  • aaa
  • fff7
  • bbb
  • ccc
  • fff
  • 得出这样的结果
  • table
  • select

得分解答快速导航

  • 帖主:delian

相关链接

  • Oracle类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo