distinct 只能对单列进行去重并,只能显示一列;
user_activte_daily_history(server_num string,app_code,static_date date,field string,industry string)
上表安装server_num(手机号进行去重)
前提条件
确保表中有有id自增类,没有的可以添加
1.create table user_active_daily_rn as select *,row_number() over(order by static_date) as rn
from user_active_daily
2.select * from user_active_daily_rn
where rn in
(select max(rn) from user_active_daily_rn + group by serv_number)
order by serv_number,static_date
获取本周的数据可以采用next_day函数来界定本周一与本周日的日期时间,取得自然周
select next_day('2020-06-14','monday') --下周一的日期
select date_add(next_day('2020-06-14','monday') ,-7) --本周一的日期
select date_add(next_day('2020-06-14','monday'),-1) --本周日的日期
获取一个月的数据可以采用date_format()函数,对日期进行格式化,自然月
select *,row_number() over(order by static_date) as rn from
(select serv_number,filed,static_date
from user_active_daily_history " +
where date_format(static_date,'yyyy-MM') = date_format(add_months(date_sub(current_date,1),-1), 'yyyy-MM')