怎么看网站建设有多久,wordpress菜单加图标,自己做网站能挣钱吗,百度商务合作电话1.最近7天连续3天登陆用户#xff0c;字段#xff0c;id#xff0c;date#xff08;已去重#xff09;
思路#xff1a; lag对时间开窗#xff08;注意时间得转换为时间戳#xff08;int类型才可以添加后续条件#xff09;#xff0c;跳行为2#xff08;连续3天字段iddate已去重
思路 lag对时间开窗注意时间得转换为时间戳int类型才可以添加后续条件跳行为2连续3天前2行没有值的默认为0 转化时间字段为时间戳减去它上2条的那条数据的时间戳得出是否为连续登陆3天的差值第三天减去第一天的时间戳为(2 * 24 * 60 * 60 Where 过滤出最近7天的数据 对id进行分组过滤差值为2 * 24 * 60 * 60的数据 答案 select id
from (select id, date, (unix_timestamp(date) - lag(unix_timestamp(date), 2, 0) over (partition by id order by date)) lofrom toms) t1
where date between date_sub(current_date(), interval 7 day) and current_date()
group by id
having min(lo) 2 * 24 * 60 * 60;
2.字段idsend_timedatetime类型soc需求soc大于100并且持续5s会被告警求出所有数据告警和不告警输出字段idsend_timesoc持续时间告警状态0不告警1告警
思路 判断soc是否大于100如果是的给它一个自增项用于对告警的数据进行分组否则取0得到字段flag 对flag字段进行求出截止到当前的最大值得到字段flag2用于得到一整段分组的告警组 对flag2字段进行开窗分组求充电时间最小值得到字段over_time 时间相减判断如果大于5状态置为1
答案
select charge_id,soc,daq_time,timestampdiff(second, over_time, daq_time) stay_length,if(timestampdiff(second, over_time, daq_time) 5, 1, 0) status
from (select *, min(daq_time) over (partition by flag2 order by daq_time) over_timefrom (select charge_id,soc,daq_time,flag,max(flag)over (partition by charge_id order by daq_time rows between unbounded preceding and current row ) flag2from (select charge_id,soc,daq_time,if(abs(soc) 100, 0, row_number() over (partition by charge_id order by daq_time )) flagfrom demo) t1) t2) t3;