0% found this document useful (0 votes)
29 views4 pages

Lirio JohnRafael BSCS2B

Uploaded by

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

Lirio JohnRafael BSCS2B

Uploaded by

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

Cavite State University Naic Lab Activity 4

Bucana, Naic, Cavite DCIT 55: Advanced Database


Second Semester: 2023 – 2024 Management System
Instructor: Mr. Henry R. Balanza BSSC 2A/2B/BSIT 2B

Name: John Rafael M. LirioTING RA

Program, Year & Section : BSCS 2B

I. Directions: Write the correct SQL code for the following problems below and show the possible output after the
query.

Salesman salesman_id | name | city


| commission
-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12

Customer customer_id | cust_name | city |


grade | salesman_id
-------------+----------------+------------+-------+-------------
3002 | Nick Rimando | New York | 100 | 5001
3007 | Brad Davis | New York | 200 |
5001
3005 | Graham Zusi | California | 200 | 5002
3008 | Julian Green | London | 300 |
5002
3004 | Fabian Johnson | Paris | 300 | 5006
3009 | Geoff Cameron | Berlin | 100 | 5003 3003 |
Jozy Altidor | Moscow | 200 |
5007 3001 | Brad Guzan | London |
| 5005

Orders

ord_no purch_amt ord_date customer_id salesman_id


---------- ---------- ---------- ----------- -----------
70001 150.5 2012-10-05 3005 5002
70009 270.65 2012-09-10 3001 5005
70002 65.26 2012-10-05 3002 5001
70004 110.5 2012-08-17 3009 5003
70007 948.5 2012-09-10 3005 5002
70005 2400.6 2012-07-27 3007 5001
70008 5760 2012-09-10 3002 5001
70010 1983.43 2012-10-10 3004 5006
70003 2480.4 2012-10-10 3009 5003
70012 250.45 2012-06-27 3008 5002
70011 75.29 2012-08-17 3003 5007
70013 3045.6 2012-04-25 3002 5001
1. From the given tables write a SQL query to find the salesperson and customer who reside in the same
city. Return Salesman, cust_name and city. Use Aliases in every table.

SQL Query:

SELECT s.name AS "Salesman", c.cust_name, c.city FROM


salesman As s, customer As c WHERE s.city = c.city; Output:
Salesman cust_name city
James Hoog Nick Rimando New York
James Hoog Brad Davis New York
Pit Alex Julian Green London
Mc Lyon Fabian Johnson Paris
Nail Knite Fabian Johnson Paris
Pit Alex Brad Guzan London
2. From the given tables write a SQL query to find those orders where the order amount exists between
500 and 2000. Return ord_no, purch_amt, cust_name, city. Use Aliases in every table. Use Aliases in every
table.

SQL Query:

SELECT o.ord_no, o.purch_amt, c.cust_name, c.city


FROM orders o JOIN customer c ON o.customer_id = c.customer_id WHERE
o.purch_amt BETWEEN 500 AND 2000;

Output:

ord_no purch_amt cust_name city 70009


270.65 Brad Guzan London
70010 1983.43 Fabian Johnson Paris
70003 2480.4 Geoff Cameron Berlin

3. From the given tables write a SQL query to find the salesperson(s) and the customer(s) he represents.
Return Customer Name, city, Salesman, commission. Use Aliases in every table.

SQL Query:

SELECT c.cust_name, c.city, s.name AS "Salesman", s.commission


FROM customer c JOIN salesman s ON c.salesman_id = s.salesman_id;

Output:

cust_name city Salesman commission


Nick Rimando New York James Hoog 0.15
Brad Davis New York James Hoog 0.15
Graham Zusi California Nail Knite 0.13
Julian Green London Nail Knite 0.13
Fabian Johnson Paris Mc Lyon 0.14
Geoff Cameron Berlin Lauson Hen 0.12
Jozy Altidor Moscow Paul Adam 0.13
Brad Guzan London Pit Alex 0.11
4. From the given tables write a SQL query to find salespeople who received commissions of more than 12
percent from the company. Return Customer Name, customer city, Salesman, commission.
Use Aliases in every table.

SQL Query:

SELECT c.cust_name, c.city, s.name AS "Salesman", s.commission


FROM customer c JOIN salesman s ON c.salesman_id = s.salesman_id
WHERE s.commission > 0.12;

Output:

cust_name city Salesman commission


Nick Rimando New York James Hoog 0.15
Brad Davis New York James Hoog 0.15
Graham Zusi California Nail Knite 0.13
Julian Green London Nail Knite 0.13
Mc Lyon Paris Mc Lyon 0.14
Jozy Altidor Moscow Paul Adam 0.13
5. From the given tables write a SQL query to locate those salespeople who do not live in the same city
where their customers live and have received a commission of more than 12% from the company. Return
Customer Name, customer city, Salesman, salesman city, commission. Use Aliases in every table.

SQL Query:

SELECT c.cust_name, c.city, s.name AS "Salesman", s.city AS "Salesman City", s.commission


FROM customer c JOIN salesman s ON c.salesman_id = s.salesman_id WHERE
c.city != s.city AND s.commission > 0.12;

Output:

cust_name city Salesman Salesman City commission Fabian Johnson Paris Mc


Lyon Paris 0.14
Geoff Cameron Berlin Lauson Hen San Jose 0.12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy