浅浅星空 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日

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看