I want to get last month data (fist day of month through last day of month). My data is in UT (universal time) and need to pull in ET (July). I need to count the number or purchases (by counting the number of rows) and returns, grouped by ID and Date/month I'm using the below query and getting an error on the count*..line (the field is Boolean)
select
date_format(date_trunc('day',at_timezone(DATE, 'America/New_York')),'%Y-%m') as DATE_NORM
, ID
, count (purchases)
, count* (case when Returns = 1 then 1 else O End)
from "ABC"."DFG"
where date_format(date_trunc('day',at_timezone(DATE, 'America/New_York')),'%Y-%m') >= date_format(date_add('day',-7, current_date)
and ID IN ('011','012')
group by 1,2;
How can I fix the query so every month I run it, it will provide the latest month data? (In this case July), and next month will provide Jul-Aug?
I'm expecting to count the numbers or purchases rows and returns
| Date | ID | Purchases | Returns |
|---|---|---|---|
| 2024-07 | 011 | 33 | 0 |
| 2024-07 | 012 | 57 | 33 |