0% found this document useful (0 votes)
6 views6 pages

Assignment 5 .1 Aishwarya

Uploaded by

deeppatel6515
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Assignment 5 .1 Aishwarya

Uploaded by

deeppatel6515
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

Assignment 5:

Advance programming inn Data Analytics

ANLY 560-90-0

Student: Aishwarya Reddy


2

SQL:

Created Two tables:

[] %%sql

CREATE TABLE IF NOT EXISTS employees (


employee_num INTEGER,

last_name TEXT,

first_name TEXT,

salary INTEGER,

dept_id INTEGER,

age INTEGER

);

CREATE TABLE IF NOT EXISTS managers (

mgr_num INTEGER,

last_name TEXT,

first_name TEXT,

salary INTEGER,

dept_id INTEGER,

age INTEGER
);

[] %%sql

INSERT INTO EMPLOYEES VALUES (1001, 'Smith','John', 62000, 500,32);

INSERT INTO EMPLOYEES VALUES (1002, 'Anderson','Jane', 87500, 500,40);

INSERT INTO EMPLOYEES VALUES (1003, 'Everest','Brad', 71000, 501,26);

INSERT INTO EMPLOYEES VALUES (1004, 'Horvath','Brain', 62000, 501,44);


3

INSERT INTO MANAGERS VALUES (101,'white','Jonathan',152000,500,38);

INSERT INTO MANAGERS VALUES (102,'Smith','Paul',120000,501,40);

INSERT INTO MANAGERS VALUES (102,'Cowgill','Richard',150000,502,50);

[] %%sql

SELECT * FROM Employees

Output:

* sqlite://

Done.

employee_num last_name first_name salary dept_id age

1001 Smith John 62000 500 32

1002 Anderson Jane 87500 500 40

1003 Everest Brad 71000 501 26

1004 Horvath Brain 62000 501 44

1.Display employees older than 30 years old (expected output: last_name, first_name, age)
[] %%sql

select last_name, first_name, age

from employees

where age > 30;


4

output:

* sqlite://

Done.

last_name first_name age

Smith John 32

Anderson Jane 40

Horvath Brain 44

2. Display employees whose first names end in “n”( expected output: last_name,
first_name)

[] %%sql

select last_name, first_name

from employees

where first_name like "%n";

output:

* sqlite://
Done.

last_name first_name

Smith John

Horvath Brain
5

3. Find managers make more than $130k and less than $160k. (expected output: last_name,
first_name, salary)

[] %%sql

SELECT last_name, first_name, salary

FROM managers

WHERE salary > 130000 AND salary < 160000;


Output:

* sqlite://
Done.

last_name first_name salary

White Jonathan 152000

Cowgill Richard 150000

4. Find employees older than his/her manager (expected output: emp_LastName,


emp_FirstName, mgr_LastName, mgr_FirstName, ageDiff) Hint: ageDiff = employees.age
– managers.age

[] %%sql

SELECT e.last_name AS emp_LastName, e.first_name AS emp_FirstName,

m.last_name AS mgr_LastName, m.first_name AS mgr_FirstName,

(e.age - m.age) AS ageDiff

FROM employees e

JOIN managers m ON e.dept_id = m.dept_id


WHERE e.age > m.age;
6

Output:

* sqlite://

Done.

emp_LastName emp_FirstName mgr_LastName mgr_FirstName ageDiff

Anderson Jane white Jonathan 2

Horvath Brain Smith Paul 4

You might also like