JustAnotherDataEnthusiast's user avatar
JustAnotherDataEnthusiast's user avatar
JustAnotherDataEnthusiast's user avatar
JustAnotherDataEnthusiast
  • Member for 4 years, 7 months
  • Last seen more than 1 year ago
  • Galway, Ireland
About

-- Set your start and end dates SET start_date = '2023-01-01'; SET end_date = '2023-10-31';

-- Set the months you're interested in SET target_months = '7,8,9,10';

-- Generate the dynamic SQL query using JavaScript SELECT EXECUTE IMMEDIATE ( SELECT 'SELECT ID, ' || LISTAGG('SUM(CASE WHEN DATE_TRUNC(''MONTH'', TO_DATE(received_month, ''YYYY-MM-DD'')) = TO_DATE(''2023-' || m || '-01'', ''YYYY-MM-DD'') THEN Volume ELSE 0 END) AS total_volume_month' || m, ', ') WITHIN GROUP (ORDER BY m) || ' FROM transactions GROUP BY ID' FROM TABLE(FLATTEN(INPUT => SPLIT(:target_months, ','))) AS months );

Badges
This user doesn’t have any gold badges yet.
This user doesn’t have any silver badges yet.
3
bronze badges
Top tags
0
Score
1
Posts
100
Posts %
Top posts