I'm trying to select CustomerID that didn't ordered in year 1977 with:

SELECT CustomerID 
FROM orders
EXCEPT 
SELECT CustomerID 
FROM orders 
WHERE YEAR(OrderDate)=1977);

the table 'orders' contains both CustomerID and OrderDate

The error is:

Error Code: 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 '(SELECT CustomerID FROM orders WHERE YEAR(OrderDate)=1977)' at line 1
有帮助吗?

解决方案

Try this::

SELECT CustomerID FROM orders WHERE YEAR(OrderDate)<>1977;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top