看网上的案例写法是这样的:
select Behaviortype,count(*) as count,concat(round(count(*)/3693030*100,2),'%') 比例,
case when Behaviortype= 'pv' then 1
When Behaviortype= ‘cart’ then concat(round((select count from behaviorcount where Behaviortype=‘cart’)/(select count from behaviorcount where Behaviortype='pv')*100,2),'%')
when Behaviortype='fav' then concat(round((select count from behaviorcount where Behaviortype='fav')/(select count from behaviorcount where Behaviortype=‘cart’)*100,2),’%’)
when Behaviortype='buy' then concat(round((select count from behaviorcount where Behaviortype=‘buy’)/(select count from behaviorcount where Behaviortype='fav')*100,2),'%')
end as 上一阶段比例
from userbehavior1
group by Behaviortype
order by count desc;
但是一直报错提示:
ERROR 1054 (42S22): Unknown column '‘cart’' in 'field list'
但这个字段是有这个取值的
而且我觉得他behaviorcount是一个视图,userbehavior1是原表,也没用任何连接语句,百度了好多没找到解决办法,尝试修改代码如下,还是报同样的错误:
Select *
from(select Behaviortype,count,concat(round(count/3693030*100,2),'%') 比例,
(
case when Behaviortype= 'pv' then 1
When Behaviortype= ‘cart’ then concat(round((select count from behaviorcount where Behaviortype=‘cart’)/(select count from behaviorcount where Behaviortype='pv')*100,2),'%')
When Behaviortype= ‘fav’ then concat(round((select count from behaviorcount where Behaviortype=‘fav’)/(select count from behaviorcount where Behaviortype=‘cart’)*100,2),'%')
When Behaviortype= ‘buy’ then concat(round((select count from behaviorcount where Behaviortype=‘buy’)/(select count from behaviorcount where Behaviortype=‘fav’)*100,2),'%')
End ) 上一阶段占比
from
behaviorcount
group by Behaviortype
order by count desc) a;
ERROR 1054 (42S22): Unknown column '‘cart’' in 'field list'