Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e23577a

Browse files
MySQL Scripts
1 parent bc48c0b commit e23577a

7 files changed

+834
-258
lines changed

‎Import Resources/hbtn_0d_tvshows.sql

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
-- MySQL dump 10.13 Distrib 5.7.8-rc, for Linux (x86_64)
2+
--
3+
-- Host: localhost Database: hbtn_0d_tvshows
4+
-- ------------------------------------------------------
5+
-- Server version 5.7.8-rc
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `tv_genres`
20+
--
21+
22+
DROP TABLE IF EXISTS `tv_genres`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `tv_genres` (
26+
`id` int(11) NOT NULL AUTO_INCREMENT,
27+
`name` varchar(256) NOT NULL,
28+
PRIMARY KEY (`id`)
29+
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
30+
/*!40101 SET character_set_client = @saved_cs_client */;
31+
32+
--
33+
-- Dumping data for table `tv_genres`
34+
--
35+
36+
LOCK TABLES `tv_genres` WRITE;
37+
/*!40000 ALTER TABLE `tv_genres` DISABLE KEYS */;
38+
INSERT INTO `tv_genres` VALUES (1,'Drama'),(2,'Mystery'),(3,'Adventure'),(4,'Fantasy'),(5,'Comedy'),(6,'Crime'),(7,'Suspense'),(8,'Thriller');
39+
/*!40000 ALTER TABLE `tv_genres` ENABLE KEYS */;
40+
UNLOCK TABLES;
41+
42+
--
43+
-- Table structure for table `tv_show_genres`
44+
--
45+
46+
DROP TABLE IF EXISTS `tv_show_genres`;
47+
/*!40101 SET @saved_cs_client = @@character_set_client */;
48+
/*!40101 SET character_set_client = utf8 */;
49+
CREATE TABLE `tv_show_genres` (
50+
`show_id` int(11) NOT NULL,
51+
`genre_id` int(11) NOT NULL,
52+
KEY `show_id` (`show_id`),
53+
KEY `genre_id` (`genre_id`),
54+
CONSTRAINT `tv_show_genres_ibfk_1` FOREIGN KEY (`show_id`) REFERENCES `tv_shows` (`id`),
55+
CONSTRAINT `tv_show_genres_ibfk_2` FOREIGN KEY (`genre_id`) REFERENCES `tv_genres` (`id`)
56+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
57+
/*!40101 SET character_set_client = @saved_cs_client */;
58+
59+
--
60+
-- Dumping data for table `tv_show_genres`
61+
--
62+
63+
LOCK TABLES `tv_show_genres` WRITE;
64+
/*!40000 ALTER TABLE `tv_show_genres` DISABLE KEYS */;
65+
INSERT INTO `tv_show_genres` VALUES (1,1),(1,2),(2,3),(2,1),(2,4),(3,5),(4,5),(5,5),(6,6),(6,1),(6,7),(6,8),(8,6),(8,1),(8,2),(8,7),(8,8),(10,5),(10,1);
66+
/*!40000 ALTER TABLE `tv_show_genres` ENABLE KEYS */;
67+
UNLOCK TABLES;
68+
69+
--
70+
-- Table structure for table `tv_shows`
71+
--
72+
73+
DROP TABLE IF EXISTS `tv_shows`;
74+
/*!40101 SET @saved_cs_client = @@character_set_client */;
75+
/*!40101 SET character_set_client = utf8 */;
76+
CREATE TABLE `tv_shows` (
77+
`id` int(11) NOT NULL AUTO_INCREMENT,
78+
`title` varchar(256) NOT NULL,
79+
PRIMARY KEY (`id`)
80+
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;
81+
/*!40101 SET character_set_client = @saved_cs_client */;
82+
83+
--
84+
-- Dumping data for table `tv_shows`
85+
--
86+
87+
LOCK TABLES `tv_shows` WRITE;
88+
/*!40000 ALTER TABLE `tv_shows` DISABLE KEYS */;
89+
INSERT INTO `tv_shows` VALUES (1,'House'),(2,'Game of Thrones'),(3,'The Big Bang Theory'),(4,'New Girl'),(5,'Silicon Valley'),(6,'Breaking Bad'),(7,'Better Call Saul'),(8,'Dexter'),(9,'Homeland'),(10,'The Last Man on Earth');
90+
/*!40000 ALTER TABLE `tv_shows` ENABLE KEYS */;
91+
UNLOCK TABLES;
92+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
93+
94+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
95+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
96+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
97+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
98+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
99+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
100+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
101+
102+
-- Dump completed on 2017年02月26日 20:57:02
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
-- MySQL dump 10.13 Distrib 5.7.8-rc, for Linux (x86_64)
2+
--
3+
-- Host: localhost Database: hbtn_0d_tvshows_rate
4+
-- ------------------------------------------------------
5+
-- Server version 5.7.8-rc
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!40101 SET NAMES utf8 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Table structure for table `tv_genres`
20+
--
21+
22+
DROP TABLE IF EXISTS `tv_genres`;
23+
/*!40101 SET @saved_cs_client = @@character_set_client */;
24+
/*!40101 SET character_set_client = utf8 */;
25+
CREATE TABLE `tv_genres` (
26+
`id` int(11) NOT NULL AUTO_INCREMENT,
27+
`name` varchar(256) NOT NULL,
28+
PRIMARY KEY (`id`)
29+
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
30+
/*!40101 SET character_set_client = @saved_cs_client */;
31+
32+
--
33+
-- Dumping data for table `tv_genres`
34+
--
35+
36+
LOCK TABLES `tv_genres` WRITE;
37+
/*!40000 ALTER TABLE `tv_genres` DISABLE KEYS */;
38+
INSERT INTO `tv_genres` VALUES (1,'Drama'),(2,'Mystery'),(3,'Adventure'),(4,'Fantasy'),(5,'Comedy'),(6,'Crime'),(7,'Suspense'),(8,'Thriller');
39+
/*!40000 ALTER TABLE `tv_genres` ENABLE KEYS */;
40+
UNLOCK TABLES;
41+
42+
--
43+
-- Table structure for table `tv_show_genres`
44+
--
45+
46+
DROP TABLE IF EXISTS `tv_show_genres`;
47+
/*!40101 SET @saved_cs_client = @@character_set_client */;
48+
/*!40101 SET character_set_client = utf8 */;
49+
CREATE TABLE `tv_show_genres` (
50+
`show_id` int(11) NOT NULL,
51+
`genre_id` int(11) NOT NULL,
52+
KEY `show_id` (`show_id`),
53+
KEY `genre_id` (`genre_id`),
54+
CONSTRAINT `tv_show_genres_ibfk_1` FOREIGN KEY (`show_id`) REFERENCES `tv_shows` (`id`),
55+
CONSTRAINT `tv_show_genres_ibfk_2` FOREIGN KEY (`genre_id`) REFERENCES `tv_genres` (`id`)
56+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
57+
/*!40101 SET character_set_client = @saved_cs_client */;
58+
59+
--
60+
-- Dumping data for table `tv_show_genres`
61+
--
62+
63+
LOCK TABLES `tv_show_genres` WRITE;
64+
/*!40000 ALTER TABLE `tv_show_genres` DISABLE KEYS */;
65+
INSERT INTO `tv_show_genres` VALUES (2,1),(2,2),(3,3),(3,1),(3,4),(4,5),(5,5),(6,5),(7,6),(7,1),(7,7),(7,8),(9,6),(9,1),(9,2),(9,7),(9,8),(11,5),(11,1);
66+
/*!40000 ALTER TABLE `tv_show_genres` ENABLE KEYS */;
67+
UNLOCK TABLES;
68+
69+
--
70+
-- Table structure for table `tv_show_ratings`
71+
--
72+
73+
DROP TABLE IF EXISTS `tv_show_ratings`;
74+
/*!40101 SET @saved_cs_client = @@character_set_client */;
75+
/*!40101 SET character_set_client = utf8 */;
76+
CREATE TABLE `tv_show_ratings` (
77+
`show_id` int(11) NOT NULL,
78+
`rate` int(11) NOT NULL DEFAULT '0',
79+
KEY `show_id` (`show_id`),
80+
CONSTRAINT `tv_show_ratings_ibfk_1` FOREIGN KEY (`show_id`) REFERENCES `tv_shows` (`id`)
81+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
82+
/*!40101 SET character_set_client = @saved_cs_client */;
83+
84+
--
85+
-- Dumping data for table `tv_show_ratings`
86+
--
87+
88+
LOCK TABLES `tv_show_ratings` WRITE;
89+
/*!40000 ALTER TABLE `tv_show_ratings` DISABLE KEYS */;
90+
INSERT INTO `tv_show_ratings` VALUES (2,0),(2,1),(2,2),(2,3),(2,4),(2,5),(2,6),(3,0),(3,1),(3,2),(3,0),(3,0),(3,1),(3,2),(3,0),(3,0),(3,1),(3,2),(3,3),(3,4),(3,0),(3,1),(3,2),(3,3),(3,4),(3,5),(3,6),(3,7),(3,8),(3,0),(3,1),(3,2),(3,0),(3,1),(3,2),(3,3),(3,4),(3,5),(3,6),(3,0),(3,1),(3,2),(4,0),(5,0),(6,0),(6,0),(6,1),(6,2),(6,3),(6,4),(6,0),(6,0),(6,1),(6,2),(6,3),(6,4),(6,5),(6,6),(6,7),(6,8),(6,0),(6,1),(6,2),(6,3),(6,4),(6,5),(6,6),(6,7),(6,8),(7,0),(7,1),(7,2),(7,0),(7,1),(7,2),(7,3),(7,4),(7,0),(7,1),(7,2),(8,0),(8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,0),(8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,0),(8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,7),(8,8),(8,0),(8,1),(8,2),(8,0),(8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,7),(8,8),(8,0),(8,1),(8,2),(8,3),(8,4),(8,0),(8,1),(8,2),(8,3),(8,4),(8,5),(8,6),(8,7),(8,8),(9,0),(9,1),(9,2),(9,0),(9,1),(9,2),(9,3),(9,4),(9,5),(9,6),(9,0),(10,0),(10,0),(10,1),(10,2),(10,3),(10,4),(10,5),(10,6),(10,7),(10,8),(10,0),(10,1),(10,2),(10,3),(10,4),(10,5),(10,6),(10,0),(10,0),(10,1),(10,2),(10,0),(10,1),(10,2),(10,3),(10,4),(10,5),(10,6),(10,7),(10,8),(10,0),(10,1),(10,2),(10,3),(10,4),(10,0),(10,1),(10,2),(10,3),(10,4),(10,5),(10,6),(10,7),(10,8),(10,0),(10,1),(10,2),(11,0),(11,1),(11,2),(11,3),(11,4);
91+
/*!40000 ALTER TABLE `tv_show_ratings` ENABLE KEYS */;
92+
UNLOCK TABLES;
93+
94+
--
95+
-- Table structure for table `tv_shows`
96+
--
97+
98+
DROP TABLE IF EXISTS `tv_shows`;
99+
/*!40101 SET @saved_cs_client = @@character_set_client */;
100+
/*!40101 SET character_set_client = utf8 */;
101+
CREATE TABLE `tv_shows` (
102+
`id` int(11) NOT NULL AUTO_INCREMENT,
103+
`title` varchar(256) NOT NULL,
104+
PRIMARY KEY (`id`)
105+
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
106+
/*!40101 SET character_set_client = @saved_cs_client */;
107+
108+
--
109+
-- Dumping data for table `tv_shows`
110+
--
111+
112+
LOCK TABLES `tv_shows` WRITE;
113+
/*!40000 ALTER TABLE `tv_shows` DISABLE KEYS */;
114+
INSERT INTO `tv_shows` VALUES (2,'House'),(3,'Game of Thrones'),(4,'The Big Bang Theory'),(5,'New Girl'),(6,'Silicon Valley'),(7,'Breaking Bad'),(8,'Better Call Saul'),(9,'Dexter'),(10,'Homeland'),(11,'The Last Man on Earth');
115+
/*!40000 ALTER TABLE `tv_shows` ENABLE KEYS */;
116+
UNLOCK TABLES;
117+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
118+
119+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
120+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
121+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
122+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
123+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
124+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
125+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
126+
127+
-- Dump completed on 2017年02月26日 21:27:35

‎Import Resources/temperatures.sql

Lines changed: 53 additions & 0 deletions
Large diffs are not rendered by default.

‎SQL - Introduction.sql

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
-- Lists all databases of my MySQL server.
2+
SHOW DATABASES;
3+
4+
-- Creates the database hbtn_0c_0 in my MySQL server.
5+
CREATE DATABASE IF NOT EXISTS `hbtn_0c_0`;
6+
7+
-- Deletes the database hbtn_0c_0 from my MySQL server.
8+
DROP DATABASE IF EXISTS `hbtn_0c_0`;
9+
10+
-- Lists all tables of a database on my MySQL server.
11+
SHOW TABLES;
12+
13+
-- Creates a table called first_table with values id and name in my MySQL server.
14+
CREATE TABLE IF NOT EXISTS `first_table` (`id` INT, `name` VARCHAR(256));
15+
16+
-- Prints the full description of the table first_table in my MySQL server.
17+
SHOW CREATE TABLE `first_table`;
18+
19+
-- Lists all rows of the table first_table in my MySQL server.
20+
SELECT * FROM `first_table`;
21+
22+
-- Inserts a new row into the table first_table in my MySQL server.
23+
INSERT INTO `first_table` (`id`, `name`) VALUES (89, "Best School");
24+
25+
-- Displays the number of records with id = 89 in the table first_table in my MySQL server.
26+
SELECT COUNT(*)
27+
FROM `first_table`
28+
WHERE `id` = 89;
29+
30+
-- Creates and fills a table second_table with attributes id, name and score in my MySQL server with multiple rows.
31+
CREATE TABLE IF NOT EXISTS `second_table` (`id` INT, `name` VARCHAR(256), `score` INT);
32+
INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (1, "John", 10);
33+
INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (2, "Alex", 3);
34+
INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (3, "Bob", 14);
35+
INSERT INTO `second_table` (`id`, `name`, `score`) VALUES (4, "George", 8);
36+
37+
-- Retrieve all records from the table second_table.
38+
-- The records are sorted in descending order based on the score.
39+
SELECT `score`, `name`
40+
FROM `second_table`
41+
ORDER BY `score` DESC;
42+
43+
-- Lists all records in the table second_table with a score >= 10 in my MySQL server.
44+
-- Records are ordered by descending score.
45+
SELECT `score`, `name`
46+
FROM `second_table`
47+
WHERE `score` >= 10
48+
ORDER BY `score` DESC;
49+
50+
-- Updates the score of Bob to 10 in the table second_table in my MySQL server.
51+
SET SQL_SAFE_UPDATES = 0;
52+
UPDATE `second_table`
53+
SET `Score` = 10
54+
WHERE `Name` = 'Bob';
55+
SET SQL_SAFE_UPDATES = 1;
56+
57+
-- Removes all records with a score <= 5 in the table second_table in my MySQL server.
58+
DELETE FROM `second_table`
59+
WHERE `score` <= 5;
60+
61+
-- Computes the average score of all records in the table second_table in my MySQL server.
62+
SELECT AVG(`score`) AS `average`
63+
FROM `second_table`;
64+
65+
-- This query lists the number of records with the same score in the table second_table in the MySQL server.
66+
-- The result set is grouped by the score column, and the count of records for each score is calculated.
67+
-- The result is then ordered in descending order based on the count.
68+
SELECT `score`, COUNT(*) AS `number`
69+
FROM `second_table`
70+
GROUP BY `score`
71+
ORDER BY `number` DESC;
72+
73+
-- Lists all records of the table second_table having a name value in my MySQL server.
74+
-- Records are ordered by descending score.
75+
SELECT `score`, `name`
76+
FROM `second_table`
77+
WHERE `name` != ""
78+
ORDER BY `score` DESC;
79+
80+
-- Converts the entire database hbtn_0c_0 to UTF8.
81+
82+
USE hbtn_0c_0;
83+
ALTER TABLE first_table
84+
MODIFY COLUMN name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
85+
86+
-- Displays the average temperature (in Fahrenheit) by city ordered by descending temperature.
87+
SELECT `city`, AVG(`value`) AS `avg_temp`
88+
FROM `temperatures`
89+
GROUP BY `city`
90+
ORDER BY `avg_temp` DESC;
91+
92+
-- Displays the 3 cities with the highest average temperatures between July and August.
93+
SELECT `city`, AVG(`value`) AS `avg_temp`
94+
FROM `temperatures`
95+
WHERE `month` = 7 OR `month` = 8
96+
GROUP BY `city`
97+
ORDER BY `avg_temp` DESC
98+
LIMIT 3;
99+
100+
-- Displays the max temperature of each state, ordered by state name.
101+
SELECT `state`, MAX(`value`) AS `max_temp`
102+
FROM `temperatures`
103+
GROUP BY `state`
104+
ORDER BY `state`;
105+
106+
107+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /