0

ロールアップを使用する場合、すべての子レコードに親キーが必要です。alasql とロールアップを使用してこれを解決する簡単な方法はありますか?

レポートで子行を表示/非表示にするために使用されます。

レポートには複数レベルの小計があります。1 人の子供が新しい子供を持つことができます。

アグリゲーター関数に 3 つ以上のパラメーターを含めることは可能ですか?


2016 年 5 月 18 日更新:

ドリルダウン付きのアカウント レポートを作成したいと考えています。カスタム関数を使用してレベルとレベルの説明を取得することで、なんとか機能させることができました。leveldescription と level は、各集計で正しいテキストを取得するためのカスタム関数です。filterDimension は、値の配列をフィルタリングするためのカスタム関数です。

SELECTGROUPS、ROLLUPGROUPS、および FIELDSGROUPS は、ユーザーが行ったカスタム グループ化に置き換えられます。

これにより、子の表示と非表示の主な問題が解決されます。ここで、最後の集計のすべての詳細を 1 つのフィールドに表示したいと考えています。このソリューションに基づいて、カスタム関数「CHILDREN(a._) as children」を使用しましたhttps://github.com/agershun/alasql/issues/571

しかし、集計の最上位レベルでのみ詳細を表示したいと考えています。これで、集計のレベルごとに子を取得できます。

ロールアップ レベルは、最後のレベルの詳細を表示する前にユーザーがドリルダウンするフィールド (R1 .. R12) に基づいています。

alasql.aggr.CHILDREN = function(val, acc, stage) { console.log(stage); if(stage == 1 || stage == 2) { if(typeof acc == 'undefined') { if(val && Object.keys(val).length > 0) { return [val]; } else {
return; } } else { acc.push(val); return acc; } } else { return acc; } };

                SET @data = ?;
                SET @year = ?;
                SET @r1s = ?;

                with reportdefinition as 
                (
                   select * from @data
                ), data as 
                ( 
                   SELECT * FROM (
                     SELECT c1.yr, 
                            c1.acno, 
                            c1.acnm,
                            c1.webpg,
                            c1.txt,
                            c1.r1, c1.r1nm,
                            c1.r2, c1.r2nm,
                            c1.r3, c1.r3nm,
                            c1.r4, c1.r4nm,
                            c1.r5, c1.r5nm,
                            c1.r6, c1.r6nm,
                            c1.r7, c1.r7nm,
                            c1.r8, c1.r8nm,
                            c1.r9, c1.r9nm,
                            c1.r10, c1.r10nm,
                            c1.r11, c1.r11nm,
                            c1.r12, c1.r12nm,
                            CASE WHEN pr = 1 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as jan,      
                            CASE WHEN pr = 2 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as feb,      
                            CASE WHEN pr = 3 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as mar,      
                            CASE WHEN pr = 4 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as apr,      
                            CASE WHEN pr = 5 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as may,      
                            CASE WHEN pr = 6 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as jun,      
                            CASE WHEN pr = 7 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as jul,      
                            CASE WHEN pr = 8 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as aug,      
                            CASE WHEN pr = 9 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as sep,      
                            CASE WHEN pr = 10 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as oct,      
                            CASE WHEN pr = 11 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as nov,      
                            CASE WHEN pr = 12 AND c1.bgno = 0 THEN c1.acam ELSE 0 END as dec,      
                            CASE WHEN c1.bgno = 0 THEN c1.acam ELSE 0 END tot,          
                            CASE WHEN pr = 1 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as jan_bg,      
                            CASE WHEN pr = 2 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as feb_bg,      
                            CASE WHEN pr = 3 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as mar_bg,      
                            CASE WHEN pr = 4 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as apr_bg,      
                            CASE WHEN pr = 5 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as may_bg,      
                            CASE WHEN pr = 6 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as jun_bg,      
                            CASE WHEN pr = 7 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as jul_bg,      
                            CASE WHEN pr = 8 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as aug_bg,      
                            CASE WHEN pr = 9 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as sep_bg,      
                            CASE WHEN pr = 10 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as oct_bg,     
                            CASE WHEN pr = 11 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as nov_bg,      
                            CASE WHEN pr = 12 AND c1.bgno = 2015 THEN c1.acam ELSE 0 END as dec_bg,      
                            CASE WHEN c1.bgno = 2015 THEN c1.acam ELSE 0 END tot_bg      
                    FROM table1 AS c1      
                    WHERE c1.yr = @year.id      
                    AND c1.pr <= 5      
                    AND (c1.bgno = 0 or c1.bgno = 2015)
                    AND filterDimension("id", @r1s, r1)
                    )
                ), result as 
                (
                    select * 
                    from data as d1 
                    join reportdefinition as d2 on d1.acno >= d2.fromvalue and d1.acno <= d2.tovalue
                )
                SELECT *, leveldescription(group1, group2, group3[FIELDSGROUPS]) as description, level(group1, group2, group3[FIELDSGROUPS]) as level
                FROM (
                        SELECT rownum() as id, FIRST(group1) as group1, group2, group3, [SELECTGROUPS]
                            SUM(jan) as jan,
                            SUM(feb) as feb,
                            SUM(mar) as mar,
                            SUM(apr) as apr,
                            SUM(may) as may,
                            SUM(jun) as jun,
                            SUM(jul) as jul,
                            SUM(aug) as aug,
                            SUM(sep) as sep,
                            SUM(oct) as oct,
                            SUM(nov) as nov,
                            SUM(dec) as dec,
                            SUM(tot) as tot,
                            SUM(jan_bg) as jan_bg,
                            SUM(feb_bg) as feb_bg,
                            SUM(mar_bg) as mar_bg,
                            SUM(apr_bg) as apr_bg,
                            SUM(may_bg) as may_bg,
                            SUM(jun_bg) as jun_bg,
                            SUM(jul_bg) as jul_bg,
                            SUM(aug_bg) as aug_bg,
                            SUM(sep_bg) as sep_bg,
                            SUM(oct_bg) as oct_bg,
                            SUM(nov_bg) as nov_bg,
                            SUM(dec_bg) as dec_bg,
                            SUM(tot_bg) as tot_bg,
                            CHILDREN(a._) as children
                        FROM result AS a
                        GROUP BY ROLLUP(group2, group3[ROLLUPGROUPS]) 
                        ORDER BY group2, group3[FIELDSGROUPS]
                )
                ORDER BY CASE WHEN id = 1 THEN 2 ELSE 1 END, id;    

4

0 に答える 0