select 
    date_format(v.visit_time, '%Y-%m-%d') as date,
    concat
   (round(count(distinct case when o.user_id is not null then v.user_id end)*100 / count(distinct v.user_id), 1),'%') as cr
from  visit_tb as v 
    left join order_tb as o on o.user_id = v.user_id
    and date(o.order_time) = date(v.visit_time)
group by date
order by date
#写了很久,主要是下单人数和访问人数区分不开,原理不熟的坏处体现出来了,接下来去刷原理课。下面写代码的时候要减少debug的过程,写完不管怎么样,先运行,能出答案最好,不行再改的做法隐患很大。
#百分号添加concat(col,'%')
#left join和join
#写的不太规范,但是大写我实在看不习惯啊
#join 里添加and条件