Reputation: 13
Hey I can't get this case statement to work, would someone mind telling what is wrong with the syntax is.
SELECT standards.standard_id, standards.title, standards.level,standards.credits, SUM(standards.credits), standards.assessment
CASE WHEN standards.assessment = 1 THEN 'External' ELSE 'Internal' END CASE
FROM standards JOIN courses_standards ON standards.standard_id = courses_standards.standard_id
WHERE courses_standards.course_id = 1
The exact error is:
1064 - 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 'CASE WHEN standards.assessment = 1 THEN 'External' ELSE 'Internal' END CASE FR' at line 3
Upvotes: 1
Views: 261
Reputation: 598
There's a syntax error with how you're ending your case. You need to provide an Alias for when you end the case.
SELECT standards.standard_id, standards.title, standards.level,standards.credits, SUM( standards.credits), standards.assessment,
CASE WHEN standards.assessment = 1 THEN 'External' ELSE 'Internal' END assessment
FROM standards JOIN courses_standards ON standards.standard_id = courses_standards. standard_id
WHERE courses_standards.course_id = 1
Upvotes: 0