该 SQL 语句报错是因为在 case 语句中最后一个 else 后面多了一个逗号 ',',应该将其删除。正确的 SQL 语句如下:

select sum(price),
case   `event` 
when 'buy'
then '商城购买'
when  'deposit'
then  '存入'
when  'roll'
then  'roll房'
when  'box_prize_obtain'
then  '开箱'
when  'item_to_gold'
then  '兑换P豆'
when  'third_withdraw_uu'
then  'UU取回'
when  'third_withdraw_zbt'
then  'zbt取回'
when  'withdraw_order'
then  '人工取回'
when  'activity_exchange'
then  '活动获取'
when  'berlin_wheel_activity'
then  '柏林活动奖品'
when  'match_rank_reward'
then  '排行榜奖品'
else ''
end as event,
FROM_UNIXTIME(create_time, '%Y-%m-%d') as date 
from vp_user_inventory_history ih join vp_user_inventory_history_item hi on ih.id =hi.history_id 
where user_id !=94 and user_id >0
group by date,event;

另外,最后一行的 select 语句没有给出任何条件,无法执行,需要根据需要添加相应的条件。

SQL 语句错误:case 语句中多余的逗号导致报错

原文地址: https://www.cveoy.top/t/topic/n0Yt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录