Skip to content

Commit 7fe8eca

Browse files
authored
Add files via upload
1 parent 29cd4a7 commit 7fe8eca

39 files changed

+4875
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# IBM: Databases and SQL for Data Science
2+
3+
<img src="https://i.imgur.com/YCFnjvg.png" alt="Smiley face" height="300" width="600">
4+
5+
![IBM](http://i.imgur.com/Qktqnu1.png) INSTRUCTORS
6+
#### Instructors: Rav Ahuja
7+
8+
## Course Description
9+
10+
You will create new tables and be able to move data into them. You will learn common operators and how to combine the data. You will use case statements and concepts like data governance and profiling. You will discuss topics on data, and practice using real-world programming assignments. You will interpret the structure, meaning, and relationships in source data and use SQL as a professional to shape your data for targeted analysis purposes.
11+
12+
## Topics include
13+
14+
#### Week 1 - Databases and SQL
15+
- Explain SQL and Relational Databases
16+
- Create a database instance on the Cloud
17+
- Learn how to write SQL statements
18+
- Practice SQL statements hands-on on a live database
19+
20+
#### Week 2 - Advanced SQL
21+
- Explain how to use string patterns and ranges in SQL queries
22+
- Demonstrate how to sort and order result sets
23+
- Practice use of grouping data in result sets
24+
- Employ Built-in functions in Queries
25+
- Demonstrate how to write sub-queries and nested selects
26+
- Build queries to access multiple tables
27+
28+
#### Week 3 - Accessing Databases using Python
29+
- Describe concepts related to accessing Databases using Python
30+
- Learn and Practice how to connect to a database from a Jupyter notebook
31+
- Understand and demonstrate how to create tables and insert data from Python
32+
- Write SQL queries and retrieve result sets from Python
33+
- Practice how to perform simplified database access from Python using SQL magic
34+
- Enumerate different type of JOIN operations
35+
- Explain what is an INNER JOIN and practice hands-on
36+
- Distinguish between different types of OUTER JOINs and apply your understanding
37+
38+
This course is part of the 'IBM Data Science Professional Certificate'
39+
![IBM](https://i.imgur.com/j6yW3WS.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- 0. Drop table INSTRUCTOR in case it already exists
2+
drop table INSTRUCTOR
3+
;
4+
--1. Create table INSTRUCTOR
5+
CREATE TABLE INSTRUCTOR
6+
(ins_id INTEGER PRIMARY KEY NOT NULL,
7+
lastname VARCHAR(15) NOT NULL,
8+
firstname VARCHAR(15) NOT NULL,
9+
city VARCHAR(15),
10+
country CHAR(2)
11+
)
12+
;
13+
--2A. Insert single row for Rav Ahuja
14+
INSERT INTO INSTRUCTOR
15+
(ins_id, lastname, firstname, city, country)
16+
VALUES
17+
(1, 'Ahuja', 'Rav', 'Toronto', 'CA')
18+
;
19+
--2B. Insert the two rows for Raul and Hima
20+
INSERT INTO INSTRUCTOR
21+
VALUES
22+
(2, 'Chong', 'Raul', 'Toronto', 'CA'),
23+
(3, 'Vasudevan', 'Hima', 'Chicago', 'US')
24+
;
25+
--3. Select all rows in the table
26+
SELECT * FROM INSTRUCTOR
27+
;
28+
--3b. Select firstname, lastname and country where city is Toronto
29+
SELECT firstname, lastname, country from INSTRUCTOR where city='Toronto'
30+
;
31+
--4. Change the city for Rav to Markham
32+
UPDATE INSTRUCTOR SET city='Markham' where ins_id=1
33+
;
34+
--5. Delete the row for Raul Chong
35+
DELETE FROM INSTRUCTOR where ins_id=2
36+
;
37+
--5b. Retrieve all rows from the table
38+
SELECT * FROM INSTRUCTOR
39+
;
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Drop the PETSALE table in case it exists
2+
drop table PETSALE;
3+
-- Create the PETSALE table
4+
create table PETSALE (
5+
ID INTEGER PRIMARY KEY NOT NULL,
6+
ANIMAL VARCHAR(20),
7+
QUANTITY INTEGER,
8+
SALEPRICE DECIMAL(6,2),
9+
SALEDATE DATE
10+
);
11+
-- Insert saple data into PETSALE table
12+
insert into PETSALE values
13+
(1,'Cat',9,450.09,'2018-05-29'),
14+
(2,'Dog',3,666.66,'2018-06-01'),
15+
(3,'Dog',1,100.00,'2018-06-04'),
16+
(4,'Parrot',2,50.00,'2018-06-04'),
17+
(5,'Dog',1,75.75,'2018-06-10'),
18+
(6,'Hamster',6,60.60,'2018-06-11'),
19+
(7,'Cat',1,44.44,'2018-06-11'),
20+
(8,'Goldfish',24,48.48,'2018-06-14'),
21+
(9,'Dog',2,222.22,'2018-06-15')
22+
23+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
select SUM(SALEPRICE) from PETSALE;
2+
select SUM(SALEPRICE) AS SUM_OF_SALEPRICE from PETSALE;
3+
select MAX(QUANTITY) from PETSALE;
4+
select AVG(SALEPRICE) from PETSALE;
5+
select AVG( SALEPRICE / QUANTITY ) from PETSALE where ANIMAL = 'Dog';
6+
select ROUND(SALEPRICE) from PETSALE;
7+
select LENGTH(ANIMAL) from PETSALE;
8+
select UCASE(ANIMAL) from PETSALE;
9+
select DISTINCT(UCASE(ANIMAL)) from PETSALE;
10+
select * from PETSALE where LCASE(ANIMAL) = 'cat';
11+
select DAY(SALEDATE) from PETSALE where ANIMAL = 'Cat';
12+
select COUNT(*) from PETSALE where MONTH(SALEDATE)='05';
13+
select (SALEDATE + 3 DAYS) from PETSALE;
14+
select (CURRENT DATE - SALEDATE) from PETSALE;
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2,Architect Group,30001,L0001
2+
5,Software Group,30002,L0002
3+
7,Design Team,30003,L0003
4+
5,Software Group,30004,L0004
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
E1001,John,Thomas,123456,01/09/1976,M,"5631 Rice, OakPark,IL",100,100000,30001,2
2+
E1002,Alice,James,123457,07/31/1972,F,"980 Berry ln, Elgin,IL",200,80000,30002,5
3+
E1003,Steve,Wells,123458,08/10/1980,M,"291 Springs, Gary,IL",300,50000,30002,5
4+
E1004,Santosh,Kumar,123459,07/20/1985,M,"511 Aurora Av, Aurora,IL",400,60000,30004,5
5+
E1005,Ahmed,Hussain,123410,01/04/1981,M,"216 Oak Tree, Geneva,IL",500,70000,30001,2
6+
E1006,Nancy,Allen,123411,02/06/1978,F,"111 Green Pl, Elgin,IL",600,90000,30001,2
7+
E1007,Mary,Thomas,123412,05/05/1975,F,"100 Rose Pl, Gary,IL",650,65000,30003,7
8+
E1008,Bharath,Gupta,123413,05/06/1985,M,"145 Berry Ln, Naperville,IL",660,65000,30003,7
9+
E1009,Andrea,Jones,123414,07/09/1990,F,"120 Fall Creek, Gary,IL",234,70000,30003,7
10+
E1010,Ann,Jacob,123415,03/30/1982,F,"111 Britany Springs,Elgin,IL",220,70000,30004,5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
100,Sr. Architect,60000,100000
2+
200,Sr. Software Developer,60000,80000
3+
300,Jr.Software Developer,40000,60000
4+
400,Jr.Software Developer,40000,60000
5+
500,Jr. Architect,50000,70000
6+
600,Lead Architect,70000,100000
7+
650,Jr. Designer,60000,70000
8+
660,Jr. Designer,60000,70000
9+
234,Sr. Designer,70000,90000
10+
220,Sr. Designer,70000,90000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
E1001,08/01/2000,100,2
2+
E1002,08/01/2001,200,5
3+
E1003,08/16/2001,300,5
4+
E1004,08/16/2000,400,5
5+
E1005,05/30/2000,500,2
6+
E1006,08/16/2001,600,2
7+
E1007,05/30/2002,650,7
8+
E1008,05/06/2010,660,7
9+
E1009,08/16/2016,234,7
10+
E1010,08/16/2016,220,5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
L0001,2
2+
L0002,5
3+
L0003,7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- Query 1------
2+
;
3+
select F_NAME , L_NAME
4+
from EMPLOYEES
5+
where ADDRESS LIKE '%Elgin,IL%' ;
6+
--Query 2--
7+
;
8+
select F_NAME , L_NAME
9+
from EMPLOYEES
10+
where B_DATE LIKE '197%' ;
11+
---Query3--
12+
;
13+
select *
14+
from EMPLOYEES
15+
where (SALARY BETWEEN 60000 and 70000) and DEP_ID = 5 ;
16+
--Query4A--
17+
;
18+
select F_NAME, L_NAME, DEP_ID
19+
from EMPLOYEES
20+
order by DEP_ID;
21+
--Query4B--
22+
;
23+
select F_NAME, L_NAME, DEP_ID
24+
from EMPLOYEES
25+
order by DEP_ID desc, L_NAME desc;
26+
--Query5A--
27+
;
28+
select DEP_ID, COUNT(*)
29+
from EMPLOYEES
30+
group by DEP_ID;
31+
--Query5B--
32+
;
33+
select DEP_ID, COUNT(*), AVG(SALARY)
34+
from EMPLOYEES
35+
group by DEP_ID;
36+
--Query5C--
37+
;
38+
select DEP_ID, COUNT(*) AS "NUM_EMPLOYEES", AVG(SALARY) AS "AVG_SALARY"
39+
from EMPLOYEES
40+
group by DEP_ID;
41+
--Query5D--
42+
;
43+
select DEP_ID, COUNT(*) AS "NUM_EMPLOYEES", AVG(SALARY) AS "AVG_SALARY"
44+
from EMPLOYEES
45+
group by DEP_ID
46+
order by AVG_SALARY;
47+
--Query5E--
48+
;
49+
select DEP_ID, COUNT(*) AS "NUM_EMPLOYEES", AVG(SALARY) AS "AVG_SALARY"
50+
from EMPLOYEES
51+
group by DEP_ID
52+
having count(*) < 4
53+
order by AVG_SALARY;
54+
--5E alternative: if you want to use the label
55+
select DEP_ID, NUM_EMPLOYEES, AVG_SALARY from
56+
( select DEP_ID, COUNT(*) AS NUM_EMPLOYEES, AVG(SALARY) AS AVG_SALARY from EMPLOYEES group by DEP_ID)
57+
where NUM_EMPLOYEES < 4
58+
order by AVG_SALARY;
59+
--BONUS Query6--
60+
;
61+
select D.DEP_NAME , E.F_NAME, E.L_NAME
62+
from EMPLOYEES as E, DEPARTMENTS as D
63+
where E.DEP_ID = D.DEPT_ID_DEP
64+
order by D.DEP_NAME, E.L_NAME desc ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
-- Query 1------
2+
;
3+
select F_NAME , L_NAME
4+
from EMPLOYEES
5+
where ADDRESS LIKE '%Elgin,IL%' ;
6+
--Query 2--
7+
;
8+
select F_NAME , L_NAME
9+
from EMPLOYEES
10+
where B_DATE LIKE '197%' ;
11+
---Query3--
12+
;
13+
select *
14+
from EMPLOYEES
15+
where (SALARY BETWEEN 60000 and 70000) and DEP_ID = 5 ;
16+
--Query4A--
17+
;
18+
select F_NAME, L_NAME, DEP_ID
19+
from EMPLOYEES
20+
order by DEP_ID;
21+
--Query4B--
22+
;
23+
select F_NAME, L_NAME, DEP_ID
24+
from EMPLOYEES
25+
order by DEP_ID desc, L_NAME desc;
26+
--Query5A--
27+
;
28+
select DEP_ID, COUNT(*)
29+
from EMPLOYEES
30+
group by DEP_ID;
31+
--Query5B--
32+
;
33+
select DEP_ID, COUNT(*), AVG(SALARY)
34+
from EMPLOYEES
35+
group by DEP_ID;
36+
--Query5C--
37+
;
38+
select DEP_ID, COUNT(*) AS "NUM_EMPLOYEES", AVG(SALARY) AS "AVG_SALARY"
39+
from EMPLOYEES
40+
group by DEP_ID;
41+
--Query5D--
42+
;
43+
select DEP_ID, COUNT(*) AS "NUM_EMPLOYEES", AVG(SALARY) AS "AVG_SALARY"
44+
from EMPLOYEES
45+
group by DEP_ID
46+
order by AVG_SALARY;
47+
--Query5E--
48+
;
49+
select DEP_ID, COUNT(*) AS "NUM_EMPLOYEES", AVG(SALARY) AS "AVG_SALARY"
50+
from EMPLOYEES
51+
group by DEP_ID
52+
having count(*) < 4
53+
order by AVG_SALARY;
54+
--5E alternative: if you want to use the label
55+
select DEP_ID, NUM_EMPLOYEES, AVG_SALARY from
56+
( select DEP_ID, COUNT(*) AS NUM_EMPLOYEES, AVG(SALARY) AS AVG_SALARY from EMPLOYEES group by DEP_ID)
57+
where NUM_EMPLOYEES < 4
58+
order by AVG_SALARY;
59+
--BONUS Query6--
60+
;
61+
select D.DEP_NAME , E.F_NAME, E.L_NAME
62+
from EMPLOYEES as E, DEPARTMENTS as D
63+
where E.DEP_ID = D.DEPT_ID_DEP
64+
order by D.DEP_NAME, E.L_NAME desc ;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
------------------------------------------
2+
--DDL statement for table 'HR' database--
3+
--------------------------------------------
4+
5+
CREATE TABLE EMPLOYEES (
6+
EMP_ID CHAR(9) NOT NULL,
7+
F_NAME VARCHAR(15) NOT NULL,
8+
L_NAME VARCHAR(15) NOT NULL,
9+
SSN CHAR(9),
10+
B_DATE DATE,
11+
SEX CHAR,
12+
ADDRESS VARCHAR(30),
13+
JOB_ID CHAR(9),
14+
SALARY DECIMAL(10,2),
15+
MANAGER_ID CHAR(9),
16+
DEP_ID CHAR(9) NOT NULL,
17+
PRIMARY KEY (EMP_ID));
18+
19+
CREATE TABLE JOB_HISTORY (
20+
EMPL_ID CHAR(9) NOT NULL,
21+
START_DATE DATE,
22+
JOBS_ID CHAR(9) NOT NULL,
23+
DEPT_ID CHAR(9),
24+
PRIMARY KEY (EMPL_ID,JOBS_ID));
25+
26+
CREATE TABLE JOBS (
27+
JOB_IDENT CHAR(9) NOT NULL,
28+
JOB_TITLE VARCHAR(15) ,
29+
MIN_SALARY DECIMAL(10,2),
30+
MAX_SALARY DECIMAL(10,2),
31+
PRIMARY KEY (JOB_IDENT));
32+
33+
CREATE TABLE DEPARTMENTS (
34+
DEPT_ID_DEP CHAR(9) NOT NULL,
35+
DEP_NAME VARCHAR(15) ,
36+
MANAGER_ID CHAR(9),
37+
LOC_ID CHAR(9),
38+
PRIMARY KEY (DEPT_ID_DEP));
39+
40+
CREATE TABLE LOCATIONS (
41+
LOCT_ID CHAR(9) NOT NULL,
42+
DEP_ID_LOC CHAR(9) NOT NULL,
43+
PRIMARY KEY (LOCT_ID,DEP_ID_LOC));
44+

0 commit comments

Comments
 (0)