dear community!
I'm a bit lost with my SQL query on PRESTO. Essentially, I have a view with the following columns:
branch | year_month (varchar) | sellid [... and others]
Germany | 2022-06 | 123q1239
What I need to do is fairly simple, I need to create a table like this:
branch | year_month | count(sellid) actual month | count(sellid) last month
I attempted the following among other things, but unfortunately I'm still getting errors.
SELECT branch, year_month, count(sellid)as active_locs,
CASE
WHEN TO_DATE(year_month, '%Y-%m') = date_format(TO_DATE(year_month, '%Y-%m') - interval '1' month, '%Y-%m') THEN count(sellid) END as locs_LM
FROM table
GROUP BY branch, year_month
This is the exact error I'm getting:
An error occurred when executing the SQL command: SELECT branch, year_month, count(sellid)as active_locs, CASE WHEN TO_DATE(year_month, '%Y-%m') = date_format(TO_DATE(year_month, '%Y-%m') - interv...
Query failed (#20220628_093246_00650_e4kcc): line 3:39: '=' cannot be applied to date, varchar [DB Errorcode=1] 1 statement failed.
Could someone help me out??
Thanks in advance