例如这样一个表,我想统计email和passwords都不相同的记录的条数
CREATE TABLE IF NOT EXISTS `test_users` (
`email_id` int() unsigned NOT NULL auto_increment,
`email` char() NOT NULL,
`passwords` char() NOT NULL,
PRIMARY KEY (`email_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT= ; INSERT INTO `test_users` (`email_id`, `email`, `passwords`) VALUES
(, ‘[email protected]', ‘1e48c4420b7073bc11916c6c1de226bb'),
(, ‘[email protected]', ‘5294cef9f1bf1858ce9d7fdb62240546′),
(, ‘[email protected]', ‘5294cef9f1bf1858ce9d7fdb62240546′),
(, ‘[email protected]', ”),
(, ‘[email protected]', ”);
通常我们的做法是这样:
SELECT COUNT(*) FROM test_users WHERE = GROUP BY email,passwords
这样的结果是什么呢?
COUNT(*)
显然这不是我要的结果,这样统计出来的是相同email和passwords的各个记录数量之和,下面这样就可以了:
SELECT COUNT(DISTINCT email,passwords) FROM `test_users` WHERE =