clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2805483 fiddles created (40772 in the last week).

CREATE TABLE CI_BSEG_CALC_LN ( `BSEG_ID` INTEGER, `DST_ID` VARCHAR(8), `BILL_SQ` FLOAT, `AUDIT_CALC_AMT` FLOAT, `BILL_SQ, MSR_PEAK_QTY_SW, DESCR_ON_BILL, VERSION, AUDIT_CALC_AMT` VARCHAR(65) ); INSERT INTO CI_BSEG_CALC_LN (`BSEG_ID`, `DST_ID`, `BILL_SQ`, `AUDIT_CALC_AMT`, `BILL_SQ, MSR_PEAK_QTY_SW, DESCR_ON_BILL, VERSION, AUDIT_CALC_AMT`) VALUES ('12334', 'REV-WSC', '62', '6.40667', 'For 0 - 60 (Next 62.000 cubic meter) @US0.10 per cubic meter'), ('12334', 'REV-WSC', '62', '64.06667', 'For 60 - 120 (Next 62.000 cubic meter) @US1.00 per cubic meter'), ('12334', 'REV-WSC', '3.6', '11.16', 'For 120 - 180 (Next 3.600 cubic meter) @US3.00 per cubic meter'), ('12334', 'REV_WWSC', '62', '3.20333', 'For 0 - 60 (Next 62.000 cubic meter) @US0.05 per cubic meter'), ('12334', 'REV_WWSC', '62', '32.03333', 'For 60 - 120 (Next 62.000 cubic meter) @USSAR0.50 per cubic meter'), ('12334', 'REV_WWSC', '3.6', '5.58', 'For 120 - 180 (Next 3.600 cubic meter) @US1.50 per cubic meter'), ('11111', 'REV-WSC', '62', '6.40667', 'For 0 - 60 (Next 62.000 cubic meter) @US0.10 per cubic meter'), ('11111', 'REV-WSC', '62', '64.06667', 'For 60 - 120 (Next 62.000 cubic meter) @US1.00 per cubic meter'), ('11111', 'REV-WSC', '3.6', '11.16', 'For 120 - 180 (Next 3.600 cubic meter) @US3.00 per cubic meter'), ('11111', 'REV_WWSC', '62', '3.20333', 'For 0 - 60 (Next 62.000 cubic meter) @US0.05 per cubic meter'), ('11111', 'REV_WWSC', '62', '32.03333', 'For 60 - 120 (Next 62.000 cubic meter) @USSAR0.50 per cubic meter'), ('11111', 'REV_WWSC', '3.6', '5.58', 'For 120 - 180 (Next 3.600 cubic meter) @US1.50 per cubic meter');
 hidden batch(es)


SELECT `BSEG_ID`, `DST_ID`, SUM(`BILL_SQ` BETWEEN 0 AND 10) '0-10', SUM(`BILL_SQ` > 10 AND `BILL_SQ` <= 20) '10> <= 20', SUM(`BILL_SQ` > 20) '>20' FROM CI_BSEG_CALC_LN GROUP BY `BSEG_ID`, `DST_ID`
BSEG_ID DST_ID 0-10 10> <= 20 >20
11111 REV-WSC 1 0 2
11111 REV_WWSC 1 0 2
12334 REV-WSC 1 0 2
12334 REV_WWSC 1 0 2
 hidden batch(es)


SELECT `BSEG_ID`, `DST_ID`, SUM(`res_sum` BETWEEN 0 AND 10) '0-10', SUM(`res_sum` > 10 AND `res_sum` <= 20) '10> <= 20', SUM(`res_sum` > 20) '>20' FROM (SELECT `BSEG_ID`, `DST_ID`, SUM(`AUDIT_CALC_AMT`) res_sum FROM CI_BSEG_CALC_LN GROUP BY `BSEG_ID`, `DST_ID`) t1 GROUP BY `BSEG_ID`, `DST_ID`
BSEG_ID DST_ID 0-10 10> <= 20 >20
11111 REV-WSC 0 0 1
11111 REV_WWSC 0 0 1
12334 REV-WSC 0 0 1
12334 REV_WWSC 0 0 1
 hidden batch(es)