Mysql 聚合函数资料

    SQL 脚本:

    1. --
    2. -- Database: `movies`
    3. --
    4. -- --------------------------------------------------------
    5. --
    6. -- Table structure for table `genres`
    7. --
    8. DROP TABLE IF EXISTS `genres`;
    9. CREATE TABLE `genres` (
    10. `genre_id` int(11) NOT NULL,
    11. `genre_title` varchar(30) NOT NULL
    12. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    13. --
    14. -- Dumping data for table `genres`
    15. --
    16. INSERT INTO `genres` (`genre_id`, `genre_title`) VALUES
    17. (1, 'Fantasy'),
    18. (2, 'Sci-Fi'),
    19. (3, 'Action'),
    20. (4, 'Comedy'),
    21. (5, 'Drama'),
    22. (6, 'Horror'),
    23. (7, 'Romance'),
    24. (8, 'Family');
    25. -- --------------------------------------------------------
    26. --
    27. -- Table structure for table `movies`
    28. --
    29. DROP TABLE IF EXISTS `movies`;
    30. CREATE TABLE `movies` (
    31. `movie_id` int(11) NOT NULL,
    32. `movie_title` varchar(100) NOT NULL,
    33. `director` varchar(50) NOT NULL,
    34. `year` year(4) NOT NULL,
    35. `genre_id` int(11) NOT NULL
    36. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    37. --
    38. -- Dumping data for table `movies`
    39. --
    40. INSERT INTO `movies` (`movie_id`, `movie_title`, `director`, `year`, `genre_id`) VALUES
    41. (1, 'Labyrinth', 'Jim Henson', 1986, 1),
    42. (2, 'Highlander', 'Russell Mulcahy', 1986, 1),
    43. (3, 'Alien', 'Ridley Scott', 1979, 2),
    44. (4, 'Conan the Barbarian', 'John Milius', 1982, 1),
    45. (5, 'The Hobbit: An Unexpected Journey', 'Peter Jackson', 2012, 1),
    46. (6, 'The Dark Crystal', 'Jim Henson', 1982, 1),
    47. (7, 'Star Wars: A New Hope', 'George Lucas', 1977, 2),
    48. (8, 'Harry Potter and the Order of the Phoenix', 'David Yates', 2007, 1),
    49. (9, 'Fantastic Beasts and Where to Find Them ', 'David Yates', 2016, 1),
    50. (10, 'Excalibur', 'John Boorman', 1981, 1),
    51. (11, 'Time Bandits', 'Terry Gilliam', 1981, 1),
    52. (12, 'Pan\'s Labyrinth', 'Guillermo Del Toro', 2006, 1),
    53. (13, 'Blade Runner', 'Ridley Scott', 1982, 2),
    54. (14, 'Interstellar', 'Christopher Nolan', 2014, 2),
    55. (15, 'A.I. Artificial Intelligence', 'Steven Spielberg', 2001, 2),
    56. (16, 'The Matrix', 'The Wachowskis', 1999, 2),
    57. (17, 'Gattaca', 'Andrew Niccol', 1997, 2),
    58. (18, 'Avatar', 'James Cameron', 2009, 2),
    59. (19, 'Moon', 'Duncan Jones', 2009, 2),
    60. (20, 'Galaxy Quest', 'Dean Parisot', 1999, 2),
    61. (21, 'The Fifth Element', 'Luc Besson', 1997, 2),
    62. (22, 'Inception', 'Christopher Nolan', 2010, 2),
    63. (23, 'District 9', 'Neill Blokamp', 2009, 2),
    64. (24, 'Her', 'Spike Jonez', 2013, 2),
    65. (25, 'Pulp Fiction', 'Quentin Tarantino', 1994, 5),
    66. (26, 'Reservoir Dogs', 'Quentin Tarantino', 1992, 5),
    67. (27, 'Transcendence', 'Wally Pfister', 2014, 2),
    68. (28, 'Contact', 'Robert Zemekis', 1997, 2);
    69. -- --------------------------------------------------------
    70. --
    71. -- Table structure for table `people`
    72. --
    73. DROP TABLE IF EXISTS `people`;
    74. CREATE TABLE `people` (
    75. `email` varchar(100) NOT NULL,
    76. `first_name` varchar(30) NOT NULL,
    77. `last_name` varchar(30) NOT NULL,
    78. `common_name` varchar(40) NOT NULL
    79. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    80. --
    81. -- Dumping data for table `people`
    82. --
    83. INSERT INTO `people` (`email`, `first_name`, `last_name`, `common_name`) VALUES
    84. ('arya@stark.org', 'Arya', 'Stark', ''),
    85. ('brandon@stark.org', 'Brandon', 'Stark', 'Bran'),
    86. ('bronn@blackwater.info', 'Bronn', 'Blackwater', ''),
    87. ('cersei@lannister.com', 'Cersei', 'Lannister', ''),
    88. ('daenerys@dragonstone.org', 'Daenerys', 'Targaryen', ''),
    89. ('davos@seaworth.org', 'Davos', 'Seaworth', 'The Onion Knight'),
    90. ('gregor@clegane.org', 'Gregor', 'Clegane', ''),
    91. ('jaime@lannister.org', 'Jaime', 'Lannister', ''),
    92. ('jon@snow.org', 'Jon', 'Snow', 'King Jon the First'),
    93. ('samwell@nights-watch.org', 'Samwell', 'Tarley', ''),
    94. ('sandor@clegane.org', 'Sandor', 'Clegane', ''),
    95. ('sansa@stark.org', 'Sansa', 'Stark-Bolton', '');
    96. --
    97. -- Indexes for dumped tables
    98. --
    99. --
    100. -- Indexes for table `genres`
    101. --
    102. ALTER TABLE `genres`
    103. ADD PRIMARY KEY (`genre_id`);
    104. --
    105. -- Indexes for table `movies`
    106. --
    107. ALTER TABLE `movies`
    108. ADD PRIMARY KEY (`movie_id`);
    109. --
    110. -- Indexes for table `people`
    111. --
    112. ALTER TABLE `people`
    113. ADD PRIMARY KEY (`email`);
    114. --
    115. -- AUTO_INCREMENT for dumped tables
    116. --
    117. --
    118. -- AUTO_INCREMENT for table `genres`
    119. --
    120. ALTER TABLE `genres`
    121. MODIFY `genre_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
    122. --
    123. -- AUTO_INCREMENT for table `movies`
    124. --
    125. ALTER TABLE `movies`
    126. MODIFY `movie_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=29;