Supposed I have some sample data in table_name_a
as below:
code val_a date
-------------------------
1 00001 500 20191101
2 00001 1000 20191130
3 00002 200 20191101
4 00002 400 20191130
5 00003 200 20191101
6 00003 600 20191130
There are some val_a
of code
between 20191101 and 20191130, I would like to get the last day value of the month on every code
, and my SQL query is as below(need to match Hive
and Impla
):
SELECT code, max(date) AS date, val_a
FROM table_a
WHERE date BETWEEN '20090601'
AND '20090630'
GROUP BY code, val_a
But above query was wrong(the val_a of code is not the last day of the month),My expected output as below:
code val_a date
--------------------------
1 00001 1000 20191130
2 00002 400 20191130
3 00003 600 20191130
Thanks so much for any advice.