题解 | 查询下订单用户访问次数?
查询下订单用户访问次数?
https://www.nowcoder.com/practice/32bc1e0fce2343ad934b76a025e09fc5
可不用表合并的方法。将order_tb中筛选出的用户作为在visit_tb中查询的where条件。
※date()函数可直接提取时间的'年-月-日'。
select user_id,count(*) visit_nums from visit_tb where user_id in( select distinct user_id from order_tb where date_format(order_time,'%Y-%m-%d')='2022-09-02' ) and date_format(visit_time,'%Y-%m-%d')='2022-09-02' and date_format(leave_time,'%Y-%m-%d')='2022-09-02' group by user_id order by visit_nums desc