oracle 创交表,创建交叉报表(oracle)_oracle
創建交叉報表
create table t1(
goodid??number(10) ?not null,
saledate ?date ??not null,
salesum ?number(10)
);
要求生成本年度每個月的產品銷售狀況表
m1?m2?m3?...?m12
g1
g2
.
.
.
gn
下面是生成報表的sql
SELECT goodid,
SUM(decode(to_char(saledate,'mm'),'01',salesum)) "01",
SUM(decode(to_char(saledate,'mm'),'02',salesum)) "02",
SUM(decode(to_char(saledate,'mm'),'03',salesum)) "03",
SUM(decode(to_char(saledate,'mm'),'04',salesum)) "04",
SUM(decode(to_char(saledate,'mm'),'05',salesum)) "05",
SUM(decode(to_char(saledate,'mm'),'06',salesum)) "06",
SUM(decode(to_char(saledate,'mm'),'07',salesum)) "07",
SUM(decode(to_char(saledate,'mm'),'08',salesum)) "08",
SUM(decode(to_char(saledate,'mm'),'09',salesum)) "09",
SUM(decode(to_char(saledate,'mm'),'10',salesum)) "10",
SUM(decode(to_char(saledate,'mm'),'11',salesum)) "11",
SUM(decode(to_char(saledate,'mm'),'12',salesum)) "12"
from t1
where to_char(saledate,'yyyy') = '2004'
group by goodid
order by goodid;
歡迎大家閱讀《創建交叉報表(oracle)_oracle》,跪求各位點評,若覺得好的話請收藏本文,by 搞代碼
微信 賞一包辣條吧~
支付寶 賞一聽可樂吧~
總結
以上是生活随笔為你收集整理的oracle 创交表,创建交叉报表(oracle)_oracle的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “竦竦寒山木”下一句是什么
- 下一篇: 《楚乔传》羽姑娘真实身份是什么 最后死了