2015-09-04 235 views
0

我嘗試在我的SQL語法使用COUNT(DISTINCT ..)),這是我的SQL語法:SQL語法錯誤(COUNT(DISTINCT ..))

SELECT COUNT (DISTINCT ID) 
FROM teaches 
WHERE semester = 'Spring' AND year = 2010; 

但是,語法不工作,有什麼問題?

這是錯誤消息:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE semester = 'Spring' AND year = 2010' at line 1 

這是我的 '教' 表:

create table teaches(
    ID char(5), 
    course_id varchar(8), 
    sec_id varchar(8), 
    semester varchar(6), 
    year numeric(4,0), 
    foreign key (course_id, sec_id, semester) references section (course_id, sec_id, semester) 
) 
+0

什麼是您的錯誤信息? –

+0

這是錯誤信息,我編輯了我的問題。 –

+0

你的桌子「教」什麼結構? –

回答

4

你不能COUNT(之間的空間。更改爲

SELECT COUNT(DISTINCT ID) 

這受控於ignore_space SQL模式設置。另見Function Name Parsing and Resolution

+0

經典,但我沒有看到它,@Barmar幹得好。 –

+0

雅這是正確的,現在它的工作,謝謝:) –