SELECT
TO_CHAR(TO_DATE(TO_CHAR(C.DATE_SK),'YYYY-MM-DD'),'MON'),
A.PRODUCT,
c.REG_HOURS + c.OFF_HOURS
FROM
DIM_PRODUCT A
INNER JOIN
DIM_TICKET B ON A.PRODUCT_SK = B.PRODUCT_SK
INNER JOIN
FACT_TIMESHEET C ON C.TICKET_SK = B.TICKET_SK
GROUP BY
A.PRODUCT, c.REG_HOURS + c.OFF_HOURS,
TO_CHAR(TO_DATE(TO_CHAR(C.DATE_SK),'YYYY-MM-DD'),'MON');
我的输出如下:
+------------------------------------------------+
| col1(month) col2(product name) col3(hours) |
+------------------------------------------------+
| mar aaa 1 |
| mar aaa 2 |
| mar aaa 3 |
| apr bbb 2.5 |
| apr bbb 3 |
+------------------------------------------------+
我的预期输出如下:
+-----------------------------------------------+
| col1(month) col2(product name) col3(hours) |
+-----------------------------------------------+
| mar aaa 6 |
| apr bbb 5.5 |
+-----------------------------------------------+
答案 0 :(得分:0)
这个怎么样?
SELECT A.MONTH, A.PRODUCT_NAME, SUM(A.HOURS)
FROM (YOUR QUERY) A
GROUP BY A.MONTH, A.PRODUCT_NAME;