0% found this document useful (0 votes)
42 views5 pages

Lab. Activity - 01

The document contains examples of SQL queries to retrieve data from various tables for different conditions. The queries include finding the winning country of a soccer cup, displaying orders by a specific salesman, matching countries that played against each other, and joining tables to retrieve salesman, customer, and order details.

Uploaded by

Sadiq Ahmad
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)
42 views5 pages

Lab. Activity - 01

The document contains examples of SQL queries to retrieve data from various tables for different conditions. The queries include finding the winning country of a soccer cup, displaying orders by a specific salesman, matching countries that played against each other, and joining tables to retrieve salesman, customer, and order details.

Uploaded by

Sadiq Ahmad
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/ 5

Lab.

Activity – 01:

1. Write a query in SQL to find the name of the winner country of


Saudi cup 2018. Consider the winner as the one who wins all

matches.

select country_name from soccer_country where country_id=(SELECT


team_id
FROM (SELECT team_id,COUNT(win_lose) matches from
match_details where win_lose like 'W' group by team_id order by
COUNT(win_lose) desc limit 1));

2. Write an SQL query to display all the orders from the orders table
issued by the salesman ‘James Hoog’.

SELECT *FROM ordersWHERE salesman_id =(SELECT salesman_id


FROM salesman WHERE name=' James Hoog')
3. For the tables shown in activity 2 above, write an SQL query to display
all the orders for the salesman who belongs to the city Paris.

SELECT *FROM orders WHERE salesman_id =(SELECT salesman_id


FROM salesman WHERE city=' Paris ')

Lab. Activity – 02:

1. Write a query in SQL to find the match no in which Germany played


against Poland
SELECT match_no FROM match_details WHERE team_id=(SELECT
country_id FROM soccer_country WHERE country_name='Germany') OR
team_id=(SELECT country_id FROM soccer_country WHERE
country_name='Poland')
GROUP BY match_no HAVING COUNT(DISTINCT team_id)=2;

Lab. Activity – 01:

1. Write a SQL statement to prepare a list with salesman name, customer


name and their cities for the salesmen and customer who belongs to the
same city.
SELECT salesman.name,customer.cust_name, customer.city
FROM salesman,customer WHERE salesman.city=customer.city;

2. Write a SQL statement to make a list with order no, purchase amount,
customer name and their cities for those orders which order amount
between 500 and 2000.

SELECT orders.ord_no,orders.purch_amt,
customer.cust_name,customer.city FROM orders,customer WHERE
orders.customer_id=customer.customer_id ANd orders.purch_amt
BETWEEN 500 AND 2000;
3. Write a SQL statement to find the list of customers who appointed a
salesman for their jobs who does not live in the same city where their
customer lives, and gets a commission is above 12%.
SELECT customer.cust_name, customer.city, salesman.name, salesman.city,
salesman.commission FROM customer INNER JOIN salesman ON
customer.salesman_id=salesman.salesman_id WHERE salesman.commission>.12
AND customer.city<>salesman.city;

You might also like