全部评论
可以来这里多练习一下 https://www.nowcoder.com/ta/sql
--第一题
select coalesce(a.create_date, b.create_date) as static_date , coalesce(a.new_user_cnt, 0) as new_user_cnt , coalesce(b.order_cnt, 0) as order_cnt , coalesce(b.order_user_cnt, 0) as order_user_cnt
from ( select substr(create_time, 1, 10) as create_date , count(user_id) as new_user_cnt from user where 1 = 1 group by substr(create_time, 1, 10)
) a
full join ( select substr(create_time, 1, 10) as create_date , count(distinct user_id) as order_user_cnt , count(order_id) as order_cnt from order where 1 = 1 group by substr(create_time, 1, 10)
) b on a.create_date = b.create_date ;
--第二题
select city_id , count(user_id) as order_user_cnt , count(if(to_date(first_order_date) between between date_sub(current_date, 7) and date_sub(current_date, 1), user_id, null)) as first_order_user_cnt
from ( select user_id , city_id from order where to_date(substr(create_time, 1, 10)) between date_sub(current_date, 7) and date_sub(current_date, 1) group by user_id , city_id
) a
join ( select user_id , city_id , substr(min(create_time), 1, 10) as first_order_date from order where 1 = 1 group by user_id , city_id
) b on a.user_id = b.user_id and a.city_id = b.city_id
where 1 = 1
group by city_id ;
相关推荐
07-04 16:00
门头沟学院 Java 点赞 评论 收藏
分享
06-23 12:08
广州大学 硬件测试 小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
05-14 15:17
青岛滨海学院 Java 点赞 评论 收藏
分享

点赞 评论 收藏
分享