case when then语句 总是提示case附近有语法错误
selectcount(*)as人数casesalarywhensalary>4000andsalary<=5000then'高薪'whensalary>=1000and...
select
count(*) as 人数
case salary
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end as '等级'
from telenolist
group by
case salary
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end 展开
count(*) as 人数
case salary
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end as '等级'
from telenolist
group by
case salary
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end 展开
展开全部
不要写case salary,而是case when salary.
因为后边是大于小于的条件,所以不能case salary
如果case salary,when要这么写 when 5000 then '' when 10000 then ...
后边就是salary的具体情况,而不是判断式了。
select
count(*) as 人数
case
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end as '等级'
from telenolist
group by
case
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end
因为后边是大于小于的条件,所以不能case salary
如果case salary,when要这么写 when 5000 then '' when 10000 then ...
后边就是salary的具体情况,而不是判断式了。
select
count(*) as 人数
case
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end as '等级'
from telenolist
group by
case
when salary>4000 and salary<=5000 then '高薪'
when salary>=1000 and salary<=4000 then '低薪'
else 'null'
end
追问
我也改过,还是提示“case附近有语法错误”,刚才我把你的答案复制到我的查询分析器里边了。。又试了一边。还是这个提示
追答
逗号呢?人数后边的逗号
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询