我尝试在我的SQL语法中使用COUNT(DISTINCT ..)),这是我的SQL语法:
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 :(得分:4)
COUNT
和(
之间不能有空格。改为
SELECT COUNT(DISTINCT ID)
这由ignore_space
SQL模式设置控制。另请参阅Function Name Parsing and Resolution。