on 06-08-2015 10:51 AM
Hi All,
I have table with data Region, product,month, sales amount with data in HANA DB.I want to calculate the region wise sales percentage on the total sales in hana studio.(Some thing like % GT in BW).
Region | PRODUCT | MONTH | Header 4 |
---|---|---|---|
R1 | P1 | JAN | 100 |
R1 | P1 | JAN | 200 |
R2 | P2 | JAN | 300 |
R2 | P1 | FEB | 100 |
R3 | P2 | MAR | 100 |
My output should be
Region | sales percentage |
---|---|
R1 | =300/800 => 37.5% |
R2 | =400/800 => 50% |
R3 | =100/800 => 12.5% |
i started doing using procedure but could not arrive to get final output. Any suggestions / ways to get % sales of region.
BEGIN
DECLARE V_SALES DOUBLE;
VAR = SELECT SUM(SALES_AMOUNT) FROM "JOSE_HANA"."SALES";
OUTPUT_TABLE = SELECT "REGION_ID", ( SUM(SALES_AMOUNT) / VAR * 100) AS SALES_PERC
FROM "JOSE_HANA"."SALES"
GROUP BY "REGION_ID"
ORDER BY SUM(SALES_AMOUNT) DESC;
END;
Try the below mentioned code :
BEGIN
DECLARE V_SALES DOUBLE;
DECLARE VAL DOUBLE;
SELECT SUM(NETVAL) INTO VAL FROM "TEST"."SALES";
OUTPUT_TABLE = SELECT "REGION", ( SUM(NETVAL) / VAL * 100) AS SALES_PERC
FROM "TEST"."SALES"
GROUP BY "REGION"
ORDER BY SUM(NETVAL) DESC;
END;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.