Created
November 3, 2010 00:30
-
-
Save ZenCocoon/660594 to your computer and use it in GitHub Desktop.
With SQL, how to achieve the following goal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `users` ( | |
`id` int(11) DEFAULT NULL, | |
`email` varchar(255) CHARACTER SET latin1 DEFAULT NULL, | |
`born_at` varchar(255) CHARACTER SET latin1 DEFAULT NULL | |
) ENGINE=MyISAM DEFAULT CHARSET=utf8; | |
INSERT INTO `users` (`id`,`email`,`born_at`) VALUES ('1','[email protected]','1980-01-01'); | |
INSERT INTO `users` (`id`,`email`,`born_at`) VALUES ('2','[email protected]','1980-01-02'); | |
INSERT INTO `users` (`id`,`email`,`born_at`) VALUES ('3','[email protected]','1980-01-01'); | |
INSERT INTO `users` (`id`,`email`,`born_at`) VALUES ('4','[email protected]','1980-01-03'); | |
INSERT INTO `users` (`id`,`email`,`born_at`) VALUES ('5','[email protected]','1980-01-02'); | |
INSERT INTO `users` (`id`,`email`,`born_at`) VALUES ('6','[email protected]','1980-01-02'); | |
# Desired format | |
# count_with_similar_born_at_but_different_email born_at | |
2 1980-01-01 | |
2 1980-01-02 | |
1 1980-01-03 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution : SELECT born_at, COUNT(DISTINCT(email)) FROM users GROUP BY born_at