簡單的sql語句,由于自己水平一般,不知道錯在哪里...忘熟悉語句的人指導(dǎo)一二,謝謝!select new_name as 年度,count(new_name) as 總份數(shù),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 產(chǎn)品的銷售價格打分from filterednew_surveygroup by new_name為什么這句提示關(guān)鍵字 '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 產(chǎn)品的銷售價格打分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 產(chǎn)品的銷售價格打分from filterednew_surveygroup by new_name這句也沒有問題請各位指導(dǎo)下~~~經(jīng)過幾位的幫忙,我自己修改了一下,改成select new_name as 年度,count(new_name) as 總份數(shù),round(sum(case new_q01 when '0' then filterednew_survey.new_q01else (isnull(filterednew_survey.new_q01,1.00)-1.00)end),2) as 產(chǎn)品的銷售價格打分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 產(chǎn)品的銷售價格打分from filterednew_surveygroup by new_name為什么這句的也是is null then 0就可以呢?
2 回答

慕少森
TA貢獻2019條經(jīng)驗 獲得超9個贊
select new_name as 年度,
count(new_name) as 總份數(shù),
round(sum(case isnull(new_q01,0) when '0' then '0'
else(filterednew_survey.new_q01-1.00) end),2) as 產(chǎn)品的銷售價格打分
from filterednew_survey
group by new_name
改成這個試一下
-------------------------------
when new_q01 is null then 0
else 1 end
這個是不行的 你會發(fā)現(xiàn) 不管他是不是null 他返回的都是1

拉風(fēng)的咖菲貓
TA貢獻1995條經(jīng)驗 獲得超2個贊
ISNULL使用指定的替換值替換 NULL。
語法
ISNULL ( check_expression , replacement_value )
IS NULL 是兩個關(guān)鍵字,在一起用是判斷指定的內(nèi)容是否是 null
兩個似乎沒有什么可比性
添加回答
舉報
0/150
提交
取消