Board logo

標題: 學習SQL遇到小問題 [列印本頁]

作者: google107543386    時間: 2014-8-16 23:01     標題: 學習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
作者: michael    時間: 2014-8-17 00:42

回復 1# google107543386

把兩個 'Total Salary'改為TotalSalary就可以正常排序了(TotalSalary中間不要有空格)
作者: fb1000001971834    時間: 2014-10-20 16:29

當我輸入
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這幾個欄位  但是底下資料完全是空的

請問是我語法有打錯嗎?
作者: google107549365    時間: 2014-10-27 09:30

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

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




歡迎光臨 CodeData 技術論譠 (http://www.codedata.com.tw/forum/) Powered by Discuz! 7.2