问题:
开发一个关于各烟叶等级的二次验级的原发件数、原发重量及验收重量的统计报表。其中,原发件数、原发重量和验收重量等列要求计算出各等级组别的小计和所有记录的合计。
语句:
SELECT DECODE(GROUPING(T4.TOBACCO_CLASS_TYPE) + GROUPING(T1.TOBACCO_CLASS_NAME),
1,
DECODE(T4.TOBACCO_TYPE,
51, ‘上等烟小计’,
52, ‘中等烟小计’,
53, ‘下等烟小计’,
54, ‘低等烟小计’,
‘小计’),
2,
‘合计’,
T1.TOBACCO_CLASS_NAME
) TOBACCO_CLASS_NAME,
T4.TOBACCO_CLASS_TYPE,
NVL(SUM(T1.ORG_PIECE),0) TOTAL_ORG_PIECE,
NVL(SUM(T1.ORG_WEIGHT), 0) TOTAL_ORG_WEIGHT,
NVL(SUM(T1.AMOUNT), 0) TOTAL_AMOUNT
FROM VI_FK_BALANCE_DETAIL T1, TB_TOBACCO_CLASS T4
WHERE T1.TOBACCO_CLASS_ID=T4.TOBACCO_CLASS_ID
AND T1.ACCOUNT_YEAR=T4.ACCOUNT_YEAR
AND T4.DEL_FLAG=0
AND T4.ENABLE_FLAG=0
AND T1.REC_DATE > TO_DATE(‘2006-11-05’, ‘YYYY-MM-DD’
GROUP BY ROLLUP( T4.TOBACCO_CLASS_TYPE,T1.TOBACCO_CLASS_NAME)
ORDER BY T4.TOBACCO_CLASS_TYPE
通过查询得到统计结果如下表所示,该表的统计结果已经满足了统计要求。
烟叶等级 |
等级组别 |
原发件数 |
原发重量 |
验收重量 |
(B1F)上桔一 |
51 |
4945 |
197800 |
197508.1 |
(B2F)上桔二 |
51 |
8335 |
333400 |
332316.9 |
(C1F)中桔一 |
51 |
694 |
27760 |
27610.54 |
(C2F)中桔二 |
51 |
803 |
32120 |
31650.4 |
(C3F)中桔三 |
51 |
6381 |
255240 |
255372.6 |
(X1F)下桔一 |
51 |
75 |
3000 |
3012.2 |
上等烟小计 |
51 |
21233 |
849320 |
847470.8 |
(B3F)上桔三 |
52 |
4701 |
188040 |
187389.9 |
(B4F)上桔四 |
52 |
122 |
4880 |
4866.81 |
(C3V)中微青三 |
52 |
174 |
6960 |
6934.06 |
(C4F)中桔四 |
52 |
4639 |
185560 |
185276.4 |
(X2F)下桔二 |
52 |
1739 |
69560 |
69029.79 |
(X2V)下微青二 |
52 |
26 |
1040 |
1038.34 |
(X3F)下桔三 |
52 |
1263 |
50520 |
50439.86 |
中等烟小计 |
52 |
12664 |
506560 |
504975.1 |
(X4F)下桔四 |
53 |
102 |
4080 |
4075.62 |
下等烟小计 |
53 |
102 |
4080 |
4075.62 |
(B3K)上杂三 |
54 |
0 |
0 |
249.39 |
低等烟小计 |
54 |
0 |
0 |
249.39 |
合计 |
|
33999 |
1359960 |
1356771 |