Created
July 10, 2012 18:40
-
-
Save sorbing/3085424 to your computer and use it in GitHub Desktop.
DB Dump. Subquery in LEFT JOIN ON...
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 `stats` ( | |
`user_id` int(10) unsigned NOT NULL, | |
`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, | |
`type` varchar(10) NOT NULL, | |
PRIMARY KEY (`date`,`type`,`user_id`), | |
KEY `fk_user_id_1` (`user_id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |
INSERT INTO `stats` (`user_id`, `date`, `type`) VALUES | |
(1, '2012-06-30 21:00:00', 'тип №1'), | |
(1, '2012-07-02 09:30:00', 'тип №1'), | |
(1, '2012-07-03 11:40:00', 'тип №1'), | |
(2, '2012-07-10 18:10:36', 'тип №2'); | |
-- -------------------------------------------------------- | |
CREATE TABLE IF NOT EXISTS `user` ( | |
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, | |
`user` varchar(50) DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; | |
INSERT INTO `user` (`id`, `user`) VALUES | |
(1, 'Вася'), | |
(2, 'Коля'); | |
ALTER TABLE `stats` | |
ADD CONSTRAINT `fk_user_id_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment