圆函数

时间:2015-10-29 09:02:16

标签: mysql sql

如果聊天评分为4或5,则评分很高。聊天的评分为1/2/3/4/5。但是,我提交的代码在使用case语句时会抛出错误

  

(#1064 - 您的SQL语法有错误;请查看手册   对应于您的MySQL服务器版本,以便使用正确的语法   在'case cs.chat_rating附近(4,5)然后GR时(1,2,3,4,5)然后TR   在第4行结束WHERE cs.ag'。

另外我认为我对圆函数和除法运算符的使用可能是错误的。我需要找到好评与总评分的比率。

SELECT Distinct(cm.channel_name), round(GR DIV TR) FROM channel_company AS cc
    LEFT JOIN chat_sessions 
    LEFT JOIN channel_master
    case cs.chat_rating
    when (4,5) then GR 
    when (1,2,3,4,5) then TR end
    WHERE cs.agent_assigned_time >= " "
    AND cs.agent_assigned_time <= " "
    group by 1

1 个答案:

答案 0 :(得分:0)

SELECT cm.channel_name,
(SUM(case 
    when cs.chat_rating IN (4,5) then 1 ELSE 0 END) / SUM(case when cs.chat_rating IS NOT NULL then 1 ELSE 0 END)) AS ratio_rating 
    FROM
    channel_company as cc 
    LEFT JOIN chat_sessions AS cs ON cs.company_id = cc.company_id
    LEFT JOIN channel_master AS cm ON cc.channel_id = cm.id
    WHERE cs.agent_assigned_time >= '2015-10-28 06:30:00'
    AND cs.agent_assigned_time <= '2015-10-29 02:30:00'
    group by cm.channel_name

您在CASE条件下错过了IN位置和一些WHEN。您必须在cc中提及FROM的正确表别名(您错过了它) ) 希望这有帮助