ITPub博客

首页 > 数据库 > 数据库开发技术 > 一条SQL语句的书写

一条SQL语句的书写

原创 数据库开发技术 作者:fanhongjie 时间:2008-05-19 12:50:52 0 删除 编辑

目的,输出表中所有客户名称,尺度可能存在的组合,如果该组合上没有数量,则以0代替.

custom_name :客户名称

rsize:尺度

qty:数量

表名:custom01

[@more@]

表中记录如下:

客户名称 尺度 数量
中国 20 10
中国 60 40
中国 80 50
德国 40 60
德国 80 70


其中尺度有20 40 60 80
输出变为下面的格式

客户名称 尺度 数量
中国 20 10
中国 40 0
中国 60 40
中国 80 50
德国 20 0
德国 40 60
德国 60 0
德国 80 70

实现的SQL语句如下:

select c.custom_name,c.rsize,nvl(d.qty,0) from (select a.custom_name, b.rsize
from (select distinct custom_name from custom01) a,
(select distinct rsize from custom01) b) c,
custom01 d
where c.custom_name=d.custom_name(+)
and c.rsize=d.rsize(+)
group by c.custom_name,c.rsize,d.qty

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/73920/viewspace-1004230/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: Oracle Events
请登录后发表评论 登录
全部评论

注册时间:2008-05-22

  • 博文量
    111
  • 访问量
    685243