开发者

mysql compare enum

Here is a table i have

CREATE TABLE `CUSTOMERSTATUSTYPES` (
  `CustomerStatusId` int(1) unsigned NOT NU开发者_如何学运维LL auto_increment,
  `CustomerStatusName` enum('ACTIVE','SUSPEND','TERMINATE','CANCEL') default NULL,
  PRIMARY KEY  (`CustomerStatusId`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

When i write

GROUP BY ... WHERE cst.CustomerStatusName<>'TERMINATE' ;

i get a syntax error

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 cst.CustomerStatusName<>'TERMINATE'' at line 1

How do i correctly check this?


The WHERE clause must come before the GROUP BY clause.


You either need to put the WHERE clause before the GROUP BY clause, or you need to use the HAVING keyword.

See here for more info:

http://www.databasejournal.com/features/mysql/article.php/3469351/The-HAVING-and-GROUP-BY-SQL-clauses.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜