top

學習SQL遇到小問題

關於下列語法,為何不能以 'Total Salary' 進行排序?是有顯示,但是無法真的有排序
select ename, salary,hiredate,
case
when year(hiredate)<1980 then salary*2.5
when year(hiredate)>=1980 and year(hiredate)<1985 then salary*2.0
else salary*1.5
end 'Total Salary'
from cmdev.emp
order by 'Total Salary' asc

Select Continent,Code2,name,IndepYear From world.country Where Continent = 'Africa' AND IndepYear is NULL;

將"="改成"is", 試試看.

TOP

當我輸入
Select Continent,Code2,name,IndepYear From world.country Where Continent = 'Africa'
有跑出Continent  ,Code2  ,name  ,IndepYear
並且在 IndepYear 欄位中有看到幾筆為NULL的項目

但是當我在多加一個條件時
Select Continent,Code2,name,IndepYear From world.country Where Continent = 'Africa' AND IndepYear = NULL
Continent  ,Code2  ,name  ,IndepYear
錯次訊息  有跑出Continent  ,Code2  ,name  ,IndepYear這幾個欄位  但是底下資料完全是空的

請問是我語法有打錯嗎?

TOP

回復 1# google107543386

把兩個 'Total Salary'改為TotalSalary就可以正常排序了(TotalSalary中間不要有空格)

TOP