目的,输出表中所有客户名称,尺度可能存在的组合,如果该组合上没有数量,则以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博客 ” ,链接:http://blog.itpub.net/73920/viewspace-1004230/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/73920/viewspace-1004230/