Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

SQL Exercises

The document provides SQL exercises focused on retrieving data from a 'salesman' table, including displaying all salespeople, specific columns, and filtering by city. It also includes queries for customer and order tables, demonstrating how to extract specific information based on given criteria. Sample SQL code and expected output are provided for each exercise to illustrate the results of the queries.

Uploaded by

ashefikir01
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL Exercises

The document provides SQL exercises focused on retrieving data from a 'salesman' table, including displaying all salespeople, specific columns, and filtering by city. It also includes queries for customer and order tables, demonstrating how to extract specific information based on given criteria. Sample SQL code and expected output are provided for each exercise to illustrate the results of the queries.

Uploaded by

ashefikir01
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Display All Salespeople

SQL Basic Select Statement: Exercise-1 with

Solution
Write a SQL statement that displays all the information about all salespeople.

Sample table: 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
Sample Solution:

SQL Code:
SELECT *

FROM salesman;

Output of the Query:


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
Note: Use * to get a complete list of the columns from a table.

Write a SQL statement to display specific columns such as names and


commissions for all salespeople.
Write a query to display the columns in a specific order, such as order date,
salesman ID, order number, and purchase amount for all orders.
From the following table, write a SQL query to locate salespeople who live
in the city of 'Paris'. Return salesperson's name, city.

Sample table

Output of the Query:


name city
Nail Knite Paris
Mc Lyon Paris
From the following table, write a SQL query to find customers whose grade
is 200. Return customer_id, cust_name, city, grade, salesman_id.

Sample table: customer


Output of the Query:
customer_id cust_name city grade salesman_id
3007 Brad Davis New York 200 5001
3005 Graham Zusi California 200 5002
3003 Jozy Altidor Moscow 200 5007
From the following table, write a SQL query to find orders that are
delivered by a salesperson with ID. 5001. Return ord_no, ord_date,
purch_amt.

Sample table: orders

SELECT ord_no, ord_date, purch_amt


FROM Orders
WHERE sales_id = “5001”

Output of the Query:


ord_no ord_date purch_amt
70002 2012-10-05 65.26
70005 2012-07-27 2400.60
70008 2012-09-10 5760.00
70013 2012-04-25 3045.60
____________________________________

1. From the following table, write a SQL query to find out which nurses have
not yet been registered. Return all the fields of nurse table.

You might also like