浅浅星空 2022-10-23 11:34 采纳率: 66.7%
浏览 43
已结题

SQL Case when 提示列不存在

看网上的案例写法是这样的:

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'
  • 写回答

2条回答 默认 最新

  • auto_rommel 2022-10-23 11:57
    关注

    英文单引号,不是中文单引号

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月31日
  • 已采纳回答 10月23日
  • 创建了问题 10月23日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改