I have 2 questions for the following query output:
COALESCE(Division,'Grand Total') Divi,
COALESCE(Section,'DivTotal') Sec,
COALESCE(m.Department,'SecTotal') Dept,
COALESCE(Assortment,'DeptTotal') Assort,
COALESCE(Promo,'') Prom,
COALESCE(Range_Details,'') Range_,
SUM(`WH STK`) WH_STK,
SUM(`AL STK QTY`) AL_STK,
SUM(`AL SAL QTY`) AL_SAL,
SUM(`AL LYa`) LY_a,
SUM(`AL LYb`) LY_b,
SUM(`AL MIN`) AL_MIN,
b.LYa_tot,
b.LYb_tot,
COALESCE(ROUND(((SELECT b.LYb_tot)/(SELECT b.LYa_tot))* COALESCE(SUM(`AL SAL QTY`),0),0),0) 'upcoming',
COALESCE((ROUND(((SELECT b.LYb_tot)/(SELECT b.LYa_tot))*SUM(`AL SAL QTY`),0) + SUM(`AL MIN`)) - SUM(`AL STK QTY`),0) 'Dispatch'
FROM
(.....I have removed rest of the query part to make it short....) m
GROUP BY
m.Division,
m.Section,
m.Department,
m.Assortment,
m.Promo,
m.Range_Details WITH ROLLUP HAVING
(Division IS NOT NULL AND Section IS NOT NULL AND Department IS NULL AND Assortment IS NULL AND Promo IS NULL AND Range_Details IS NULL )
OR (Division IS NOT NULL AND Section IS NOT NULL and Section NOT IN ('OTHERS','W_ACCESSORIES','W_BOTTOMWEAR','W_INNERWEAR','W_UPPERWEAR') AND Department IS NOT NULL AND Assortment IS NULL AND Promo IS NULL AND Range_Details IS NULL )
OR (Division IS NOT NULL AND Section NOT IN ('OTHERS','W_ACCESSORIES','W_BOTTOMWEAR','W_INNERWEAR','W_UPPERWEAR') AND Department IS NOT NULL and Department NOT IN ('GLOVE','RAINCOAT','SWIM SUIT','CORD TROUSERS','COTTON TROUSERS','FORMAL TROUSERS') AND Assortment IS NOT NULL AND Promo IS not NULL AND Range_Details IS not NULL )
OR (Division IS NULL AND Section IS NULL AND Department IS NULL AND Assortment IS NULL AND Promo IS NULL AND Range_Details IS NULL )
enter image description here 1.) How do I keep only 'Grand Total' in last row and remove 'DivTotal','SecTotal', 'DeptTotal'.
2.) Is there any better option to use "WITH ROLLUP" so that I get to chose only columns where I need subtotal instead of having subtotal for all columns in GROUP BY clause?
Note: I am already using multiple UNION, so if possible please give solution without union. cant embed image, apologies for the inconvenience.