Created
June 9, 2015 12:15
-
-
Save morontt/d7b467c1237bc6b1175c to your computer and use it in GitHub Desktop.
SQL query
This file contains 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 IF NOT EXISTS `phone_call` ( | |
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | |
`user` varchar(16) NOT NULL, | |
`flag` int(10) unsigned NOT NULL, | |
`length` int(10) unsigned NOT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM DEFAULT CHARSET=utf8; | |
INSERT INTO `phone_call` (`id`, `user`, `flag`, `length`) VALUES | |
(1, 'pupkin', 0, 12), | |
(2, 'pupkin', 1, 13), | |
(3, 'pupkin', 0, 11), | |
(4, 'vasya', 1, 23), | |
(5, 'pupkin', 1, 2), | |
(6, 'vasya', 1, 3), | |
(7, 'pupkin', 0, 5), | |
(8, 'vasya', 0, 7); |
This file contains 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
SELECT `user`, SUM(`length` * `flag`) AS `day`, SUM(`length` * (1 - `flag`)) AS `night` | |
FROM `phone_call` | |
GROUP BY `user`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment