2015-09-04 228 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

雅这是正确的,现在它的工作,谢谢:) –