为了账号安全,请及时绑定邮箱和手机立即绑定

关于SQL 简单的语法问题,isnull,内容太长,具体的情况如下所示

关于SQL 简单的语法问题,isnull,内容太长,具体的情况如下所示

慕慕森 2021-05-30 09:06:08
简单的sql语句,由于自己水平一般,不知道错在哪里...忘熟悉语句的人指导一二,谢谢!select new_name as 年度,count(new_name) as 总份数,round(sum(case new_q01 when '0' then filterednew_survey.new_q01when filterednew_survey.new_q01 is null then '0'else(filterednew_survey.new_q01-1.00)end),2) as 产品的销售价格打分from filterednew_surveygroup by new_name为什么这句提示关键字 'is' 附近有语法错误???selectnew_name as year,count(new_name) as quantity,round(sum(isnull(new_q01,1.00)-1.00)/sum(casewhen new_q01 is null then 0else 1 end ),2) as 产品的销售价格打分from filterednew_surveygroup by new_name这句没有问题.selectnew_name as year,count(new_name) as quantity,round(sum(isnull(new_q01,1.00)-1.00)/sum(casewhen new_q01 is null then 0else 1 end ),2) as 产品的销售价格打分from filterednew_surveygroup by new_name这句也没有问题请各位指导下~~~经过几位的帮忙,我自己修改了一下,改成select new_name as 年度,count(new_name) as 总份数,round(sum(case new_q01 when '0' then filterednew_survey.new_q01else (isnull(filterednew_survey.new_q01,1.00)-1.00)end),2) as 产品的销售价格打分from filterednew_surveygroup by new_name也重新理解了下isnull但是有还是有点小小的不明白selectnew_name as year,count(new_name) as quantity,round(sum(isnull(new_q01,1.00)-1.00)/sum(casewhen new_q01 is null then 0else 1 end ),2) as 产品的销售价格打分from filterednew_surveygroup by new_name为什么这句的也是is null then 0就可以呢?
查看完整描述

2 回答

?
慕少森

TA贡献2019条经验 获得超9个赞

select new_name as 年度,
count(new_name) as 总份数,

round(sum(case isnull(new_q01,0) when '0' then '0'
else(filterednew_survey.new_q01-1.00) end),2) as 产品的销售价格打分

from filterednew_survey
group by new_name

改成这个试一下

-------------------------------
when new_q01 is null then 0
else 1 end
这个是不行的 你会发现 不管他是不是null 他返回的都是1

查看完整回答
反对 回复 2021-06-07
?
拉风的咖菲猫

TA贡献1995条经验 获得超2个赞

ISNULL使用指定的替换值替换 NULL。
语法
ISNULL ( check_expression , replacement_value )

IS NULL 是两个关键字,在一起用是判断指定的内容是否是 null
两个似乎没有什么可比性

查看完整回答
反对 回复 2021-06-07
  • 2 回答
  • 0 关注
  • 381 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信