-1
我有多個學校,有多個年級和各種狀態。 如果狀態爲-1或0,我需要獲得每所學校每個年級的計數。 這些都來自同一張表。 '學生' 如果等級等於0,學校等於1234 ,如果等級等於1,學校等於1234 ,如果等級等於2,學校等於1234等於1234 接下來的一行將是一個不同的學校等各行不同的學校,每列從0級水平的12SQL - 一個表 - 多個列的計數
我試圖
select Sched_NextYearGrade,
sum(case when Sched_NextYearGrade = ‘1’ then 1 else 0 end) as 'firstcount'
sum(case when Sched_NextYearGrade = '2' then 1 else 0 end) as 'secondCount'
from Students
Where (ENROLL_STATUS BETWEEN -1 AND 0)
group by Sched_NextYearGrade
我得到
ORA-00911: invalid character
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
任何人都可以幫忙嗎?在此先感謝
您在第一個「sum」中的「1」處有微軟引號。而你的列別名是不正確的。如果你確實需要一個區分大小寫的別名,你可以使用雙引號'作爲「firstCount」。但通常你想避免像瘟疫一樣。通常情況下,使用普通的不區分大小寫的標識符並不像'firstCount'那樣使用雙引號。 –