Skip to content

Commit 725a4a5

Browse files
first commit
0 parents  commit 725a4a5

File tree

61 files changed

+2003
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2003
-0
lines changed

012_Exporting_Data.sql

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
-- MySQL dump 10.13 Distrib 5.6.24, for osx10.8 (x86_64)
2+
--
3+
-- Host: 127.0.0.1 Database: tutorial1
4+
-- ------------------------------------------------------
5+
-- Server version 5.6.27
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 `users`
20+
--
21+
22+
DROP DATABASE IF EXISTS CAVE_TEST;
23+
CREATE DATABASE IF NOT EXISTS CAVE_TEST;
24+
USE CAVE_TEST;
25+
26+
DROP TABLE IF EXISTS `users`;
27+
/*!40101 SET @saved_cs_client = @@character_set_client */;
28+
/*!40101 SET character_set_client = utf8 */;
29+
CREATE TABLE `users` (
30+
`id` int(11) NOT NULL AUTO_INCREMENT,
31+
`name` text,
32+
PRIMARY KEY (`id`)
33+
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
34+
/*!40101 SET character_set_client = @saved_cs_client */;
35+
36+
--
37+
-- Dumping data for table `users`
38+
--
39+
40+
LOCK TABLES `users` WRITE;
41+
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
42+
INSERT INTO `users` VALUES (1,'Bob'),(5,'Vicky'),(6,'Sue'),(7,'Rich'),(8,'Raj');
43+
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
44+
UNLOCK TABLES;
45+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
46+
47+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
48+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
49+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
50+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
51+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
52+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
53+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
54+
55+
-- Dump completed on 2015-10-09 18:09:02

015_Some_Test_Data.sql

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- MySQL dump 10.13 Distrib 5.6.24, for osx10.8 (x86_64)
2+
--
3+
-- Host: 127.0.0.1 Database: tutorial1
4+
-- ------------------------------------------------------
5+
-- Server version 5.6.27
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 `users`
20+
--
21+
22+
DROP DATABASE IF EXISTS CAVE_TEST;
23+
CREATE DATABASE IF NOT EXISTS CAVE_TEST;
24+
USE CAVE_TEST;
25+
26+
DROP TABLE IF EXISTS `users`;
27+
/*!40101 SET @saved_cs_client = @@character_set_client */;
28+
/*!40101 SET character_set_client = utf8 */;
29+
CREATE TABLE `users` (
30+
`id` int(11) NOT NULL AUTO_INCREMENT,
31+
`name` text,
32+
`age` int(11) DEFAULT NULL,
33+
PRIMARY KEY (`id`)
34+
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=latin1;
35+
/*!40101 SET character_set_client = @saved_cs_client */;
36+
37+
--
38+
-- Dumping data for table `users`
39+
--
40+
41+
LOCK TABLES `users` WRITE;
42+
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
43+
INSERT INTO `users` VALUES (1,'Bob',46),(2,'Bob',47),(3,'Vicky',25),(4,'Raj',21),(5,'Pete',60),(6,'John',41),(7,'Mark',30),(8,'Sue',53),(9,'Don',25),(10,'John',20),(11,'Syed',33),(12,'Christina',28),(13,'Mario',19),(14,'Justin',23),(15,'Clare',49),(16,'Sarah',73),(17,'Pete',28),(18,'Steve',32),(19,'Zoe',36),(20,'Cori',17),(21,NULL,99),(22,NULL,20);
44+
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
45+
UNLOCK TABLES;
46+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
47+
48+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
49+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
50+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
51+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
52+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
53+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
54+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
55+
56+
-- Dump completed on 2015-10-12 17:15:26

020_Solutions1.sql

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
USE CAVE_TEST;
2+
3+
-- 1. Select all the rows where age is greater than 20 but less than 30
4+
select * from users where age > 20 and age < 30;
5+
6+
7+
-- 2. Select all rows where age is between 20 (inclusive) and 30 (inclusive)
8+
select * from users where age >= 20 and age <= 30;
9+
10+
11+
-- 3. Select all rows where age is between 20 (inclusive) and 30 (inclusive) and the name is not “Vicky”
12+
select * from users where (age >= 20 and age <= 30) and not name = "Vicky";
13+
14+
-- 4. Select all rows where either the name is null or the name does not contain the letter “e”
15+
select * from users where (name not like '%e%') or (name is null);
16+
17+
18+
-- 5. Select all rows for users aged between 30 and 40 whether the name contains either the letter “o” or “e”
19+
select * from users where (age > 30 and age < 40) and (name like '%o%' or name like '%e%');
20+
21+
22+
-- 6. Select all rows where either the name contains an “o” or the id is less than 5, but not both
23+
select * from users where name like '%o%' xor id < 5;

035_Solutions2.sql

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- Create the following tables in MySQL
2+
3+
-- Products
4+
5+
-- primary key
6+
-- name
7+
-- category
8+
-- sell by date
9+
-- sold or not
10+
-- moment of sale
11+
-- quantity
12+
-- weight Kg
13+
14+
use CAVE_TEST;
15+
16+
create table products(id int primary key auto_increment, name varchar(40), category enum('Baked Goods', 'Fruit and Veg', 'Dairy'),
17+
sell_by date, sold bool, moment_of_sale timestamp, quantity int, weight numeric(6,3));
18+
19+
select * from products;
20+
21+
insert into products(name, category, sell_by, sold, moment_of_sale, quantity, weight) values
22+
("Sack of Potatoes", "Fruit and Veg", "2016-10-14", true, "2015-11-01 10:23:45", 30, 10);
23+
24+
-- ---------------------------------------
25+
-- Personnel
26+
27+
-- primary key
28+
-- given name
29+
-- family name
30+
-- gender
31+
-- telephone number
32+
-- marital status
33+
-- age
34+
-- salary
35+
-- position
36+
-- date started
37+
38+
-- ---------------------------------------
39+
40+
create table personnel(id int primary key auto_increment, given_name varchar(50), family_name varchar(50), gender enum('MALE', 'FEMALE'),
41+
telephone varchar(100), married bool, age tinyint, salary int, position enum('developer', 'manager', 'CEO'), date_started date);
42+
43+
insert into personnel(given_name, family_name, gender, telephone, married, age, salary, position, date_started) values
44+
("Arnold", "Brown", "MALE", "01348908340", true, 34, 34000, 'developer', "2014-05-06");
45+
46+
47+
select * from personnel;
48+
49+
-- Address
50+
51+
-- First line
52+
-- Second line
53+
-- City
54+
-- Region
55+
-- zip/postal code
56+
-- Two letter country code
57+
58+
create table address(id int primary key auto_increment, first_line varchar(60), second_line varchar(60),
59+
city varchar(60), region varchar(60), postal_code char(7), country_code char(2));
60+
61+
insert into address(first_line, second_line, city, region, postal_code, country_code) values
62+
("The Badger Inn", "23 Church Lane", "Badgerton", "East Badgering", "BA4DER", "UK");
63+
64+
select * from address;

0 commit comments

Comments
 (0)