In snowflake SQL I use
select
to_char(date_trunc('week',column_date),'yyyy-mm-dd') as week_date
,column_name
,count (column_name) as CN
from table_name
what is the Hive SQL version to count values per week?
In snowflake SQL I use
select
to_char(date_trunc('week',column_date),'yyyy-mm-dd') as week_date
,column_name
,count (column_name) as CN
from table_name
what is the Hive SQL version to count values per week?
Assuming Monday is the first day of your week (which I'm pretty sure Oracle does too), you can use from_unixtime
and unix_timestamp
if needed.
(You can replace current_date with any date column (assuming it's yyyy-MM-dd))
cast(from_unixtime(unix_timestamp(current_date,'yyyy-MM-dd'), 'u') as int)
will get you the day of the week as a number (Monday = 1,..., Sunday = 7)
Then we can subtract that from the current date to get the first day of the week:
date_sub(from_unixtime(unix_timestamp(current_date,'yyyy-MM-dd')), cast(from_unixtime(unix_timestamp(current_date,'yyyy-MM-dd'), 'u') AS int))
Then you can group by the result of that and count.