For example, in a table like this, I want to count the number of records with different emails and passwords. Copy the code. The code is as follows: unsigned NOT NULL auto_increment,
`email` char(100) NOT NULL,
`passwords` char(64) NOT NULL, PRIMARY KEY (`email_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6;
INSERT INTO `test_users` (`email_id`, `email`, `passwords`) VALUES(1, 'jims@gmail.com', '1e48c4420b7073bc11916c6c1de226bb'),
(2, 'jims@yahoo.com.cn' , '5294cef9f1bf1858ce9d7fdb62240546′),
(3, 'default@gmail.com', '5294cef9f1bf1858ce9d7fdb62240546′),
(4, 'jims@gmail.com', ”),
(5, 'jims@gmail.com ', ”);
Usually our approach is like this
What is the result of this? Copy the code
The code is as follows:
1 1 Obviously this is not the result I want. What is counted is the number of records with the same email and passwords Sum, the following is enough
Copy the code
The code is as follows:
Of course, you can also use mysql_num_rows in php Get the number of records, but this is not efficient. You can refer to this articlemysql_num_rows VS COUNT efficiency problem analysis The above has introduced how to count the number of records COUNT DISTINCT when using GROUP BY, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.