无标题
Posted lucky_xian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无标题相关的知识,希望对你有一定的参考价值。
sql刷题经验
1. 方法:
- round(字段,2):保留两位小数;
- concat(a,b):将字符串a,b连接;
- concat(’-’,a,b):将字符串a,b以-连接;
- TIMESTAMPdiff(second, a.start_time, a.end_time):计算两个时间的秒差值;
- SUBSTRING_INDEX(AVG_play_progress,"%",1):定位到某个字符后取值;
- date_sub(max(date(start_time)), interval 30 DAY):当前时间减去天数;
- date(start_time):取日;
- month(start_time):取月;
- year(start_time):取年;
- DATE_FORMAT(DATE(end_time),’%Y-%m’):格式化日期,’%H:%i’
- window s:定义窗口,写在表名后 window s as(
partition by tag
order by
dt desc rows between current row
and 6 following
) - current row and 6 following:当前行+前6行,滑动窗口用;
- ifnull(uid,0):判空
- RANK(),dense_rank(),row_number():排序
- **WEEKDAY(order_time) NOT IN(5, 6)**得到工作日;
- 关联条件:也可以是ON 1
2. 题型:
- 连续日期:
- SQL12 连续签到领金币;
- 根据日期得到rk,然后使用(partition by uid, DATE_sub(dt, INTERVAL rk DAY) order by dt)
- 同时在线的最大人数:
- 算出进的,再算出的数据:用union all,不然会过滤掉重复数据
select
artical_id,
in_time as dt,
1 diff
from
tb_user_log
union all
select
artical_id,
out_time as dt,
-1 diff
from
tb_user_log
- 算出进的,再算出的数据:用union all,不然会过滤掉重复数据
- 近一周,近7天:
- 滑动窗口:暂时牛客不支持distinct count
window s as(
partition by tag
order by
dt desc rows between current row
and 6 following
)
https://www.nowcoder.com/practice/f301eccab83c42ab8dab80f28a1eef98?tpId=268&tags=&title=&difficulty=0&judgeStatus=0&rp=0
- 滑动窗口:暂时牛客不支持distinct count
以上是关于无标题的主要内容,如果未能解决你的问题,请参考以下文章