HQL刷题 50道

HQL刷题 50道

尚硅谷HQL刷题网站

在这里插入图片描述
在这里插入图片描述

答案

1.查询累积销量排名第二的商品

select sku_id
from (select sku_id, dense_rank() over (order by total desc) rnfrom (select sku_id, sum(sku_num) totalfrom order_detailgroup by sku_id) t1) t2
where rn = 2;

2.查询至少连续三天下单的用户

select user_id
from (select user_id,create_date,sum(if(diff > 1, 1, 0)) over (partition by user_id order by create_date) groupsfrom (select user_id,create_date,yestoday,datediff(create_date, yestoday) diff from (select user_id,create_date,lead (create_date, 1, '1970-01-01') over (partition by user_id order by create_date) as yestoday from(select user_id, create_datefrom order_infogroup by user_id, create_date)t1) t2) t3) t4
group by user_id, groups
having count (*)>=3;

3.查询各品类销售商品的种类数及销量最高的商品

select t3.category_id,cate.category_name,t3.sku_id,t3.name,t3.order_num,t3.sku_cnt
from (select category_id,sku_id,name,order_num,sku_cntfrom (select category_id,sku_id,name,order_num,count(distinct sku_id) over (partition by category_id)               sku_cnt,row_number() over (partition by category_id order by order_num desc) rnfrom (select sku.category_id, sku.sku_id, sku.name, sum(od.sku_num) order_numfrom order_detail odjoin sku_info sku on od.sku_id = sku.sku_idgroup by sku.category_id, sku.sku_id, sku.name) t1) t2where rn = 1) t3join category_info cate on t3.category_id = cate.category_id;

4 查询用户的累计消费金额及VIP等级

select user_id,create_date,sum_so_far,casewhen sum_so_far >= 0 and sum_so_far < 10000 then '普通会员'when sum_so_far >= 10000 and sum_so_far < 30000 then '青铜会员'when sum_so_far >= 30000 and sum_so_far < 50000 then '白银会员'when sum_so_far >= 50000 and sum_so_far < 80000 then '黄金会员'when sum_so_far >= 80000 and sum_so_far < 100000 then '白金会员'when sum_so_far >= 100000 then '钻石会员' end vip_level
from (select user_id,create_date,sum(total) over (partition by user_id order by create_date) sum_so_farfrom (select user_id, create_date, sum(total_amount) total from order_info group by user_id, create_date) t1order by user_id, create_date) t2;

5 查询首次下单后第二天连续下单的用户比率

select concat(round(users * 1.0 / total * 100, 1), '%') as percentage
from (select count(distinct user_id) users, totalfrom (select user_id,create_date,first_value(create_date) over (partition by user_id order by create_date) first_day,count(distinct user_id) over ()                                           totalfrom order_info) t1where datediff(create_date, first_day) = 1group by total) t2;

6 每个商品销售首年的年份、销售数量和销售金额

select sku_id, year, order_num, order_amount
from (select sku_id, year, order_num, order_amount, row_number() over (partition by sku_id order by year) rnfrom (select sku_id, year(create_date) year, sum(sku_num) order_num, sum(sku_num * price) order_amountfrom order_detailgroup by sku_id, year(create_date)) t1) t2
where rn = 1;

7 筛选去年总销量小于100的商品

select sku_id, name, order_num
from (select sku.sku_id, sku.name, sum(sku_num) order_numfrom order_detail odjoin sku_info sku on sku.sku_id = od.sku_idwhere year(od.create_date) = '2021'and datediff(od.create_date, sku.from_date) >= 30group by sku.sku_id, sku.name) t1
where order_num < 100;

8 查询每日新用户数

select login_date_first, count(distinct user_id) user_count
from (select user_id,to_date(login_ts)                                          login_date_first,row_number() over (partition by user_id order by login_ts) rnfrom user_login_detail) t1
where rn = 1
group by login_date_first;

9 统计每个商品的销量最高的日期

select sku_id,create_date,sum_num
from (select sku_id,create_date,sum_num,row_number() over (partition by sku_id order by sum_num desc,create_date) rnfrom (select sku_id, create_date, sum(sku_num) sum_numfrom order_detailgroup by sku_id, create_date) t1) t2
where rn = 1or create_date = current_date();

10 查询销售件数高于品类平均数的商品

select sku_id,name,sum_num,floor(avg_num) cate_avg_num
from (select sku_id,name,sum_num,avg(sum_num) over (partition by category_id) avg_numfrom (select sku.sku_id,sku.name,sku.category_id,sum(od.sku_num) sum_numfrom order_detail odjoin sku_info skuon od.sku_id = sku.sku_idgroup by sku.sku_id, sku.name, sku.category_id) t1) t2
where sum_num > floor(avg_num);

11 用户注册、登录、下单综合统计

select t1.user_id,to_date(t1.register_time) register_date,t1.total_login_count,t1.login_count_2021,count(*)                  order_count_2021,sum(od.total_amount)      order_amount_2021
from (select distinct user_id,first_value(login_ts) over (partition by user_id order by login_ts) register_time,count(*) over (partition by user_id)                                total_login_count,sum(if(year(login_ts) = '2021', 1, 0)) over (partition by user_id)  login_count_2021from user_login_detail) t1join order_info od on od.user_id = t1.user_id
where year(od.create_date) = '2021'
group by t1.user_id, to_date(t1.register_time),t1.total_login_count,t1.login_count_2021;

12 查询指定日期的全部商品价格

select sku_id,price
from (select sku_id,cast(tmp_price as decimal(16, 2))                        price,row_number() over (partition by sku_id order by dt desc) rnfrom (select t1.sku_id, nvl(t2.change_date, t1.from_date) dt, nvl(t2.new_price, t1.price) tmp_pricefrom (select sku_id, price, from_datefrom sku_infowhere from_date <= '2021-10-01') t1left join(select sku_id, new_price, change_datefrom sku_price_modify_detailwhere change_date <= '2021-10-01') t2 on t1.sku_id = t2.sku_id) t3) t4
where rn = 1;

13 即时订单比例

select cast(plan / total as decimal(16, 2)) percentage
from (select count(*) total, sum(if(order_date = custom_date, 1, 0)) planfrom (select user_id,order_date,custom_date,row_number() over (partition by user_id order by order_date) rnfrom delivery_info) t1where rn = 1) t2;

14 向用户推荐朋友收藏的商品

select distinct ship.user1_id user_id, f1.sku_id
from friendship_info shipjoin favor_info f1 on ship.user2_id = f1.user_idleft join favor_info f2 on f2.user_id = ship.user1_id and f2.sku_id = f1.sku_id
where f2.sku_id is null;select user_id, sku_id
from (select distinct ship.user1_id user_id, f1.sku_idfrom friendship_info shipjoin favor_info f1 on ship.user2_id = f1.user_idunion allselect user_id, sku_idfrom favor_info) t1
group by user_id, sku_id
having count(*) < 2;

15 查询所有用户的连续登录两天及以上的日期区间

select user_id, min(dt) start_date, max(dt) end_date
from (select user_id, dt, sum(if(diff > 1, 1, 0)) over (partition by user_id order by dt) numsfrom (select user_id, dt, datediff(dt, yestoday) difffrom (select user_id, dt, lag(dt, 1, '1970-01-01') over (partition by user_id order by dt) yestodayfrom (select user_id, to_date(login_ts) dtfrom user_login_detailgroup by user_id, to_date(login_ts)) t1) t2) t3) t4
group by user_id, nums
having count(*) > 1;

16 男性和女性每日的购物总金额统计

select od.create_date,sum(if(u.gender = '男', od.total_amount, 0)) total_amount_male,sum(if(u.gender = '女', od.total_amount, 0)) total_amount_female
from order_info odjoin user_info u on od.user_id = u.user_id
group by od.create_date;

17 订单金额趋势分析

select create_date,round(sum(total_amount) over (order by ts range between 172800 preceding and current row), 2) total_3d,round(avg(total_amount) over (order by ts range between 172800 preceding and current row), 2) avg_3d
from (select create_date,unix_timestamp(create_date, 'yyyy-MM-dd') ts,sum(total_amount)                         total_amountfrom order_infogroup by create_date) t1;

18.购买过商品1和商品2但是没有购买商品3的顾客

select user_id
from (select distinct order_info.user_id, order_detail.sku_idfrom order_infojoin order_detail on order_info.order_id = order_detail.order_idwhere order_detail.sku_id in (1, 2, 3)) t1
group by user_id
having sum(if(sku_id = 3, 3, 1)) = 2;

19 统计每日商品1和商品2销量的差值

select create_date,sum(if(sku_id = 1, sku_num, 0)) - sum(if(sku_id = 2, sku_num, 0)) diff
from order_detail
where sku_id in (1, 2)
group by create_date;

20 查询出每个用户的最近三笔订单

select user_id,order_id,create_date
from (select user_id,order_id,create_date,dense_rank() over (partition by user_id order by create_date desc) rnfrom order_info) t1
where rn < 4;

21 查询每个用户登录日期的最大空档期

select user_id, max(datediff(future, dt)) max_diff
from (select user_id,dt,lead(dt, 1, '2021-10-10') over (partition by user_id order by dt) futurefrom (select distinct user_id, to_date(login_ts) dt from user_login_detail) t1) t2
group by user_id;

22 查询相同时刻多地登陆的用户

select user_id
from (select u1.user_id,if(u1.login_ts <= u2.login_ts, if(u1.logout_ts >= u2.login_ts, if(u1.ip_address = u2.ip_address, 0, 1), 0),0) numfrom user_login_detail u1join user_login_detail u2 on u1.user_id = u2.user_id and u1.login_ts != u2.login_ts) t2
group by user_id
having sum(num) > 0;

23 销售额完成任务指标的商品

select distinct sku_id
from (select sku_id, sum(if(diff > 1, 1, 0)) over (partition by sku_id order by dt) numfrom (select sku_id, dt, (year(dt) - year(pass)) * 12 + month(dt) - month(pass) difffrom (select sku_id, dt, lag(dt, 1, '1970-01-01') over (partition by sku_id order by dt) passfrom (select sku_id, dtfrom (select sku_id, trunc(create_date, 'MM') dt, sum(price * sku_num) totalfrom order_detailgroup by sku_id, trunc(create_date, 'MM')) t1
--   按题目的过滤条件 where not ((sku_id = 1 and total < 21000) or (sku_id = 2 and total < 10000))where (sku_id = 1 and total >= 21000)or (sku_id = 2 and total >= 10000)) t2) t3) t4) t5
group by sku_id, num
having count(*) > 1;

24 根据商品销售情况进行商品分类

select category, count(*) cn
from (select sku_id,casewhen total <= 5000 then '冷门商品'when total <= 19999 then '一般商品'else '热门商品' end categoryfrom (select sku_id, sum(sku_num) total from order_detail group by sku_id) t1) t2
group by category;

25 各品类销量前三的所有商品 题目意思不明确 dense_rank() row_number()

select sku_id,category_id
from (select sku_id,category_id,dense_rank() over (partition by category_id order by total desc) rnfrom (select od.sku_id, sku.category_id, sum(sku_num) totalfrom order_detail odjoin sku_info sku on od.sku_id = sku.sku_idgroup by od.sku_id, sku.category_id) t1) t2
where rn < 4;

26 各品类中商品价格的中位数

select category_id,cast(avg(price) as decimal(16, 2)) medprice
from (select category_id,price,row_number() over (partition by category_id order by price) rn,count(*) over (partition by category_id)                    cnfrom sku_info) t1
where rn in (ceil((cn + 1) * 0.5), floor((cn + 1) * 0.5))
group by category_id;

27 找出销售额连续3天超过100的商品

select distinct sku_id
from order_detail
where create_date in(select distinct create_datefrom (select create_date, count(*) over (order by nums) cntfrom (select create_date,sum(if(diff > 1, 1, 0)) over (order by create_date) numsfrom (select create_date,datediff(create_date,lag(create_date, 1, '1970-01-01') over (order by create_date)) difffrom (select create_datefrom order_detailgroup by create_datehaving sum(sku_num) > 100) t1) t2) t3) t4where cnt > 2);

28 查询有新注册用户的当天的新用户数量、新用户的第一天留存率

select first_login,sum(if(diff = 0, 1, 0))                                                       register,cast((sum(if(diff = 1, 1.0, 0)) / sum(if(diff = 0, 1, 0))) as decimal(16, 2)) retention
from (select distinct user_id,to_date(min(login_ts) over (partition by user_id))                              first_login,datediff(to_date(login_ts), to_date(min(login_ts) over (partition by user_id))) difffrom user_login_detail) t1
group by first_login;

29 求出商品连续售卖的时间区间

select sku_id,min(create_date) start_date,max(create_date) end_date
from (select sku_id,create_date,sum(if(diff > 1, 1, 0)) over (partition by sku_id order by create_date) numsfrom (select sku_id,create_date,datediff(create_date,lag(create_date, 1, '1970-01-01') over (partition by sku_id order by create_date)) difffrom (select distinct sku_id, create_datefrom order_detail) t1) t2) t3
group by sku_id, nums;

30 登录次数及交易次数统计

select t1.user_id, t1.login_date, t1.login_count, nvl(t2.order_count, 0) order_count
from (select user_id, to_date(login_ts) login_date, count(*) login_countfrom user_login_detailgroup by user_id, to_date(login_ts)) t1left join(select user_id, order_date, count(*) order_countfrom delivery_infogroup by user_id, order_date) t2 on t1.user_id = t2.user_id and t1.login_date = t2.order_date;

31 按年度列出每个商品销售总额

select sku_id,year(create_date)                            year_date,cast(sum(sku_num * price) as decimal(16, 2)) sku_sum
from order_detail
group by sku_id, year(create_date);

32 某周内每件商品每天销售情况

select sku_id,sum(if(dayofweek(create_date) = 2, sku_num, 0)) monday,sum(if(dayofweek(create_date) = 3, sku_num, 0)) tuesday,sum(if(dayofweek(create_date) = 4, sku_num, 0)) wednesday,sum(if(dayofweek(create_date) = 5, sku_num, 0)) thursday,sum(if(dayofweek(create_date) = 6, sku_num, 0)) friday,sum(if(dayofweek(create_date) = 7, sku_num, 0)) saturday,sum(if(dayofweek(create_date) = 1, sku_num, 0)) sunday
from order_detail
where create_date >= '2021-09-27'and create_date <= '2021-10-03'
group by sku_id;

33 查看每件商品的售价涨幅情况(排除只有1次涨幅的)

select sku_id, price_change
from (select sku_id,row_number() over (partition by sku_id order by change_date desc)                        rn,count(*) over (partition by sku_id)                                                      cn,new_price - (lead(new_price, 1, 0) over (partition by sku_id order by change_date desc)) price_changefrom sku_price_modify_detail) t1
where rn = 1and cn > 1;

34 销售订单首购和次购分析

-- 题目实际意思
select user_id, min(create_date) first_date, max(create_date) last_date, cn
from (select user_id,create_date,cn,row_number() over (partition by user_id order by create_date) rnfrom (select o.user_id, o.create_date, count(*) over (partition by o.user_id) cnfrom sku_info skujoin order_detail od on sku.sku_id = od.sku_idjoin order_info o on o.order_id = od.order_idwhere sku.name in ('xiaomi 10', 'apple 12', 'xiaomi 13')) t1where cn > 1) t2
where rn < 3
group by user_id, cn;
-- 实际结果
select user_id, min(create_date) first_date, max(create_date) last_date, cn
from (select user_id, create_date, cnfrom (select o.user_id, o.create_date, count(*) over (partition by o.user_id) cnfrom sku_info skujoin order_detail od on sku.sku_id = od.sku_idjoin order_info o on o.order_id = od.order_idwhere sku.name in ('xiaomi 10', 'apple 12', 'xiaomi 13')) t1where cn > 1) t2
group by user_id, cn;

35 同期商品售卖分析表

select sku_id,month(create_date)                            month,sum(if(year(create_date) = 2020, sku_num, 0)) 2020_skusum,sum(if(year(create_date) = 2021, sku_num, 0)) 2021_skusum
from order_detail
-- 按题目意思 where create_date >= '2021-01-01' and create_date < '2023-01-01'
where create_date >= '2020-01-01'and create_date < '2022-01-01'
group by sku_id, month(create_date);

36 国庆期间每个品类的商品的收藏量和购买量

select t1.sku_id, t1.total sku_sum, nvl(t2.uv, 0) favor_cn
from (select sku_id, sum(sku_num) totalfrom order_detailwhere create_date >= '2021-10-01'and create_date <= '2021-10-07'group by sku_id) t1left join(select sku_id, count(distinct user_id) uvfrom favor_infowhere create_date >= '2021-10-01'and create_date <= '2021-10-07'group by sku_id) t2 on t1.sku_id = t2.sku_id;

37 统计活跃间隔对用户分级结果

select level, count(*) cn
from (select casewhen datediff(today, register) <= 7 then '新增用户'when datediff(today, login) <= 7 then '忠实用户'when datediff(today, login) < 30 then '沉睡用户'else '流失用户' end levelfrom (select distinct user_id,max(dt) over ()                     today,min(dt) over (partition by user_id) register,max(dt) over (partition by user_id) loginfrom (select distinct user_id, to_date(login_ts) dtfrom user_login_detail) t1) t2) t3
group by level;

38 连续签到领金币数

select user_id,sum(if(total % 7 > 2, floor(total / 7) * 15 + (total % 7) + 2, floor(total / 7) * 15 + (total % 7))) sum_coin_cn
from (select user_id, count(*) totalfrom (select user_id,sum(if(nums > 1, 1, 0)) over (partition by user_id order by dt) typefrom (select user_id,dt,datediff(dt, lag(dt, 1, '1970-01-01') over (partition by user_id order by dt)) numsfrom (select distinct user_id, to_date(login_ts) dtfrom user_login_detail) t1) t2) t3group by user_id, type) t4
group by user_id
order by sum_coin_cn desc;

39 国庆期间的7日动销率和滞销率

-- 固定式(要优化)
select category_id,cast(round(first / first_total, 2) as decimal(16, 2))         first_sale_rate,cast(1 - round(first / first_total, 2) as decimal(16, 2))     first_unsale_rate,cast(round(second / second_total, 2) as decimal(16, 2))       second_sale_rate,cast(1 - round(second / second_total, 2) as decimal(16, 2))   second_unsale_rate,cast(round(third / third_total, 2) as decimal(16, 2))         third_sale_rate,cast(1 - round(third / third_total, 2) as decimal(16, 2))     third_unsale_rate,cast(round(fourth / fourth_total, 2) as decimal(16, 2))       fourth_sale_rate,cast(1 - round(fourth / fourth_total, 2) as decimal(16, 2))   fourth_unsale_rate,cast(round(fifth / fifth_total, 2) as decimal(16, 2))         fifth_sale_rate,cast(1 - round(fifth / fifth_total, 2) as decimal(16, 2))     fifth_unsale_rate,cast(round(sixth / sixth_total, 2) as decimal(16, 2))         sixth_sale_rate,cast(1 - round(sixth / sixth_total, 2) as decimal(16, 2))     sixth_unsale_rate,cast(round(seventh / seventh_total, 2) as decimal(16, 2))     seventh_sale_rate,cast(1 - round(seventh / seventh_total, 2) as decimal(16, 2)) seventh_unsale_rate
from (select sku.category_id,count(distinct if(sku.from_date <= '2021-10-01', sku.sku_id, null)) first_total,count(distinct if(od.create_date = '2021-10-01', od.sku_id, null))  first,count(distinct if(sku.from_date <= '2021-10-02', sku.sku_id, null)) second_total,count(distinct if(od.create_date = '2021-10-02', od.sku_id, null))  second,count(distinct if(sku.from_date <= '2021-10-03', sku.sku_id, null)) third_total,count(distinct if(od.create_date = '2021-10-03', od.sku_id, null))  third,count(distinct if(sku.from_date <= '2021-10-04', sku.sku_id, null)) fourth_total,count(distinct if(od.create_date = '2021-10-04', od.sku_id, null))  fourth,count(distinct if(sku.from_date <= '2021-10-05', sku.sku_id, null)) fifth_total,count(distinct if(od.create_date = '2021-10-05', od.sku_id, null))  fifth,count(distinct if(sku.from_date <= '2021-10-06', sku.sku_id, null)) sixth_total,count(distinct if(od.create_date = '2021-10-06', od.sku_id, null))  sixth,count(distinct if(sku.from_date <= '2021-10-07', sku.sku_id, null)) seventh_total,count(distinct if(od.create_date = '2021-10-07', od.sku_id, null))  seventhfrom sku_info skuleft join order_detail od on sku.sku_id = od.sku_idgroup by sku.category_id) t1;

40 出平台同时在线最多的人数

select max(num) as cn
from (select sum(flag) over (order by dt) numfrom (select login_ts dt, 1 flagfrom user_login_detailunion allselect logout_ts dt, -1 flagfrom user_login_detail) t1) t2;

41 同时在线人数问题

select live_id, max(num) max_user_count
from (select live_id, sum(flag) over (partition by live_id order by dt) numfrom (select user_id, live_id, in_datetime dt, 1 flagfrom live_eventsunion allselect user_id, live_id, out_datetime dt, -1 flagfrom live_events) t1) t2
group by live_id;

42 会话划分问题

select user_id,page_id,view_timestamp,concat(user_id, '-', sum(if(diff > 60, 1, 0)) over (partition by user_id order by view_timestamp)) session_id
from (select user_id,page_id,view_timestamp,view_timestamp - lag(view_timestamp, 1, 0) over (partition by user_id order by view_timestamp) difffrom page_view_events) t1;

43 间断连续登录用户问题

select user_id, max(num) max_day_count
from (select user_id, datediff(max(dt), min(dt)) + 1 numfrom (select user_id, dt, sum(if(diff > 2, 1, 0)) over (partition by user_id order by dt) typefrom (select user_id,dt,datediff(dt, lag(dt, 1, '1970-01-01') over (partition by user_id order by dt)) difffrom (select distinct user_id, to_date(login_datetime) dtfrom login_events) t1) t2) t3group by user_id, type) t4
group by user_id;

44 日期交叉问题

select brand, sum(if(datediff(end_date, stt) >= 0, datediff(end_date, stt) + 1, 0)) promotion_day_count
from (select brand,if(max_date is null, start_date, if(start_date > max_date, start_date, date_add(max_date, 1))) stt,end_datefrom (select brand,start_date,end_date,max(end_date)over (partition by brand order by start_date rows between UNBOUNDED PRECEDING and 1 PRECEDING) max_datefrom promotion_info) t1) t2
group by brand;

45 复购率问题(注意全是90天内)

select product_id, cast(sum(if(nums > 1, 1, 0)) / count(*) as decimal(16, 2)) as cpr
from (select user_id, product_id, count(*) numsfrom (select user_id, product_id, datediff(max(order_date) over (), order_date) difffrom order_detail) t1where diff <= 90group by user_id, product_id) t2
group by product_id
order by crp desc, product_id;

46 出勤率问题

select course_id,cast(sum(if(total is null, 0, if(total > 2400, 1, 0))) / count(*) as decimal(16, 2)) adr
from (select t1.course_id, sum(unix_timestamp(l.login_out) - unix_timestamp(l.login_in)) totalfrom (select course_id, id from course_apply lateral view explode(user_id) user_id as id) t1left join user_login l on t1.course_id = l.course_id and l.user_id = t1.idgroup by t1.course_id, t1.id) t2
group by course_id;

47 打车问题

select period,count(*)                                           get_car_num,cast(avg(nvl(wait, 0)) / 60 as decimal(16, 2))     wait_time,cast(avg(nvl(dispatch, 0)) / 60 as decimal(16, 2)) dispatch_time
from (select casewhen hour(r.event_time) >= 7 and hour(r.event_time) < 9 then '早高峰'when hour(r.event_time) >= 9 and hour(r.event_time) < 17 then '工作时间'when hour(r.event_time) >= 17 and hour(r.event_time) < 20 then '晚高峰'else '休息时间' end                                         period,unix_timestamp(o.order_time) - unix_timestamp(r.event_time) wait,unix_timestamp(o.start_time) - unix_timestamp(o.order_time) dispatchfrom get_car_record rleft join get_car_order o on r.order_id = o.order_id) t1
group by period;

48 排列问题

-- 自连接
select t1.team_name team_name_1, t2.team_name team_name_2
from team t1join team t2 on t1.team_name > t2.team_name;-- 开窗聚合,炸裂函数
select team_name_1, team_name_2
from (select team_name                                                                               team_name_1,collect_list(team_name)over (order by team_name rows between 1 following and unbounded following) team_listfrom team) t2 lateral view explode(team_list) team_list as team_name_2;

49 视频热度问题

-- 结果(但是不符合题目意思)
select video_id,cast(ceil((whole / total + up + comment + retweet) / (datediff(today, max_dt) + 1)) as decimal(16, 1)) heat
from (select video_id,today,max(dt)                                 max_dt,count(*)                                total,sum(if(l.ts >= i.duration, 1, 0)) * 100 whole,sum(l.if_like) * 5                      up,count(l.comment_id) * 3                 comment,sum(l.if_retweet) * 2                   retweetfrom (select video_id,unix_timestamp(end_time) - unix_timestamp(start_time) ts,to_date(end_time)                                     dt,to_date(max(end_time) over (partition by video_id))   today,if_like,comment_id,if_retweetfrom user_video_log) ljoin video_info i on i.video_id = l.video_idwhere l.dt <= l.todayand l.dt >= date_sub(l.today, 29)group by l.video_id, today) t1
order by heat
limit 3;-- 题目意思
select video_id,cast(((whole / total + up + comment + retweet) / fresh) as decimal(16, 2)) heat
from (select video_id,30 - count(distinct dt) + 1             fresh,count(*)                                total,sum(if(l.ts >= i.duration, 1, 0)) * 100 whole,sum(l.if_like) * 5                      up,count(l.comment_id) * 3                 comment,sum(l.if_retweet) * 2                   retweetfrom (select video_id,unix_timestamp(end_time) - unix_timestamp(start_time) ts,to_date(end_time)                                     dt,to_date(max(end_time) over ())                        today,if_like,comment_id,if_retweetfrom user_video_log) ljoin video_info i on i.video_id = l.video_idwhere l.dt <= l.todayand l.dt >= date_sub(l.today, 29)group by l.video_id) t1
order by heat
limit 3;

50 员工在职人数问题

select mth,cast(sum(num) as decimal(16,2)) ps from
(select month(dt) mth,id,sum(if((dt >= en_dt and dt <= le_dt)or (dt >= en_dt and le_dt is null),1,0))/count(*) num
from cal joinemp
where dt < '2020-04-01'and dt >= '2020-01-01' group by month(dt),id) t2 group by mth;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/161579.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php 时区查看和设置

php的时区&#xff0c;关系到相关时间函数的结果 其他相关&#xff1a; linux时区设置&#xff1a;链接 pgsql时区设置&#xff1a; 一、查看可以用的时区列表 新建一个php文件&#xff0c;输入下面程序即可 <?php echo "<pre>"; var_dump(timezone_id…

IOS+Appium+Python自动化全实战教程

由于公司的产品坐落于不同的平台&#xff0c;如ios、mac、Android、windows、web。因此每次有新需求的时候&#xff0c;开发结束后&#xff0c;留给测试的时间也不多。此外&#xff0c;一些新的功能实现&#xff0c;偶尔会影响其他的模块功能正常的使用。 网上的ios自动化方面的…

计算机网络之物理层(数据通信有关)

一、概述 1.1物理层引入的目的 屏蔽掉传输介质的多样性&#xff0c;导致数据传输方式的不同&#xff1b;物理层的引入使得高层看到的数据都是统一的0,1构成的比特流 1.2.物理层如何实现屏蔽 物理层靠定义的不同的通信协议&#xff08;一般称通信规程&#xff09; 这些协议…

基于高质量训练数据,GPT-4 Turbo更出色更强大

11月7日消息&#xff0c;OpenAI在首届开发者大会上正式推出了GPT-4 Turbo。 与GPT-4相比&#xff0c;GPT-4 Turbo主要有6方面的提升&#xff1a; 1、扩展下文对话长度&#xff1a;GPT4最大只能支持8k的上下文长度&#xff08;约等于6000个单词&#xff09;&#xff0c;而GPT-4…

智能小车速通版——手把手教程

考虑到大部分学校&#xff0c;会发放简易小车来作为智能车初期培训和筛选的工具&#xff0c; 于是&#xff0c;我写一个简单的教程&#xff0c;能够实现简单小车的电磁循迹。 通过这个教程&#xff0c;能够通过简化的步骤搭建寻迹小车&#xff0c;进而了解整个智能车是如何实…

Redis-Redis持久化,主从哨兵架构详解

Redis持久化 RDB快照&#xff08;snapshot&#xff09; 在默认情况下&#xff0c; Redis 将内存数据库快照保存在名字为 dump.rdb 的二进制文件中。 你可以对 Redis 进行设置&#xff0c; 让它在“ N 秒内数据集至少有 M 个改动”这一条件被满足时&#xff0c; 自动保存一次数…

【操作系统】I/O软件层次结构

文章目录 1. 前言2. I/O软件层次结构2.1 用户层软件2.2 设备独立性软件2.3 设备驱动程序2.4 中断处理程序 1. 前言 偶然看到“程序员的护城河是什么”这个话题&#xff0c;作为一个工作两年多的程序员吧&#xff0c;经常看到网上关于各种35岁危机、裁员甚至猝死之云云。最近也…

modbus协议及modbus TCP协议

一、Modbus协议 1.起源 Modbus由Modicon公司于1979年开发&#xff0c;是一种工业现场总线协议标准。 Modbus通信协议具有多个变种&#xff0c;其中有支持串口&#xff0c;以太网多个版本&#xff0c;其中最著名的是Modbus RTU&#xff08;通信效率最高&#xff0c;基于串口&am…

springboot前后端分离项目配置https接口(ssl证书)

文章目录 说明vue.js前端部署vue.js项目axios请求配置本地创建日志文件创建Dockerfile文件配置ssl证书nginx.confvue项目打包上传创建容器部署 后端springboot项目部署配置ssl证书打包部署 补充&#xff1a;jsk证书和pfx证书补充&#xff1a;两种证书的转化JKS转PFXPFX 转 JKS …

Elasticsearch:将最大内积引入 Lucene

作者&#xff1a;Benjamin Trent 目前&#xff0c;Lucene 限制 dot_product (点积) 只能在标准化向量上使用。 归一化迫使所有向量幅度等于一。 虽然在许多情况下这是可以接受的&#xff0c;但它可能会导致某些数据集的相关性问题。 一个典型的例子是 Cohere 构建的嵌入&#x…

使用 Lhotse 高效管理音频数据集

Lhotse 是一个旨在使语音和音频数据准备更具灵活性和可访问性的 Python 库&#xff0c;它与 k2 一起&#xff0c;构成了下一代 Kaldi 语音处理库的一部分。 主要目标&#xff1a; 1. 以 Python 为中心的设计吸引更广泛的社区参与语音处理任务。 2. 为有经验的 Kaldi 用户提供…

SpringBoot——启动类的原理

优质博文&#xff1a;IT-BLOG-CN SpringBoot启动类上使用SpringBootApplication注解&#xff0c;该注解是一个组合注解&#xff0c;包含多个其它注解。和类定义SpringApplication.run要揭开SpringBoot的神秘面纱&#xff0c;我们要从这两位开始就可以了。 SpringBootApplicati…

Spring实例化对象

默认proxyBeanMethods true&#xff0c;这种方法是用的代理模式创建对象&#xff0c;每次创建都是同一个对象&#xff0c;如果改为false每次都是不同的对象 FactoryBean的使用 定义的类A&#xff0c;造出来一个类B&#xff0c;可以在创造bean之前做一些自己的个性化操作

MFS分布式文件系统

目录 集群部署 Master Servers ​Chunkservers ​编辑Clients Storage Classes LABEL mfs高可用 pacemaker高可用 ​编辑ISCSI 添加集群资源 主机 ip 角色 server1 192.168.81.11 Master Servers server2 192.168.81.12 Chunkservers server3 192.168.81.13 Chunkserver…

【产品安全平台】上海道宁与Cybellum将整个产品安全工作流程整合到一个专用平台中,保持构建的互联产品的网络安全和网络合规性

Cybellum将 整个产品安全工作流程 整合到一个专用平台中 使设备制造商能够 保持他们构建的互联产品的 网络安全和网络合规性 产品安全性对 每个人来说都不一样 每个行业的系统、工作流程和 法规都存在根本差异 因此&#xff0c;Cybellum量身定制了 Cybellum的平台和技…

为何内存不够用?微服务改造启动多个Spring Boot的陷阱与解决方案

在生产环境中我们会遇到一些问题&#xff0c;此文主要记录并复盘一下当时项目中的实际问题及解决过程。 背景简述 最初系统上线后都比较正常风平浪静的。在系统运行了一段时间后&#xff0c;业务量上升后&#xff0c;生产上发现java应用内存占用过高&#xff0c;服务器总共64…

爱创科技总裁谢朝晖荣获“推动医药健康产业高质量发展人物”

中国医药市场规模已经成为全球第二大医药市场&#xff0c;仅次于美国。近年来&#xff0c;随着中国经济的持续增长和人民生活水平的提高&#xff0c;医药市场需求不断扩大。政府对医疗卫生事业的投入也在不断加大&#xff0c;为医药行业的发展创造了良好的政策环境。为推动医药…

结构体与指针_sizeof_static_extern_函数指针数组_函数指针_回调函数

一、结构体与指针 #include <stdint.h> #include <stdlib.h> #include <stdio.h> #define up_to_down(uuu) (downdemo_t *)(uuu->beg) #define __plc__ typedef struct updemo_s{uint8_t *head;uint8_t *beg;uint8_t *end; }updemo_t; typedef struct do…

陪玩圈子系统APP小程序H5,详细介绍,源码交付,支持二开!

陪玩圈子系统&#xff0c;页面展示&#xff0c;源码交付&#xff0c;支持二开&#xff01; 陪玩后端下载地址&#xff1a;电竞开黑陪玩系统小程序&#xff0c;APP&#xff0c;H5: 本系统是集齐开黑&#xff0c;陪玩&#xff0c;陪聊于一体的专业APP&#xff0c;小程序&#xff…

Linux进程通信——共享内存

概念 共享内存&#xff08;Shared Memory&#xff09;&#xff0c;指两个或多个进程共享一个给定的存储区。 特点 共享内存是最快的一种 IPC&#xff0c;因为进程是直接对内存进行存取。 因为多个进程可以同时操作&#xff0c;所以需要进行同步。 信号量共享内存通常结合在一…