WITH daily_order as ( select date (order_time) as day, count(distinct user_id) as order_head from order_tb group by date (order_time) ), visit as ( select date (visit_time) as day, count(distinct user_id) as visit_head from visit_tb group by date (visit_time) ) select o.day as date, concat(round(o.order_head/v.visit_head * 100, 1),'%') as cr from daily_order o join visit v on o.day=v.day order by o.day asc
- 两个CTE(公用表表达式)之间需要用逗号 , 分隔
- CTE只用写一个WITH,后面可以跟多个表