Professional Documents
Culture Documents
Lab cycle-II
Lab cycle-II
1 List all customers ordered by country, then by city within each country
50 rows selected.
2 List all suppliers in the USA, Japan, and Germany, ordered by city,�then by
company name in reverse order
3 Show all orders, sorted by total amount, the largest first, within each year�
52 rows selected.
ID UNITPRICE
---------- ----------
8 40
9 97
17 39
18 62.5
20 81
43 46
51 53
56 38
59 55
63 43.9
10 rows selected.
ID UNITPRICE
---------- ----------
1 18
2 19
3 10
6 25
7 30
10 31
13 6
14 23.25
15 15.5
16 17.45
19 9.2
21 10
22 21
23 9
24 4.5
31 12.5
32 32
33 2.5
34 14
35 18
36 19
37 26
40 18.4
41 9.65
42 14
44 19.45
45 9.5
46 12
47 9.5
48 12.75
49 20
50 16.25
52 7
53 32.8
54 7.45
55 24
57 19.5
58 13.25
60 34
67 14
68 12.5
69 36
70 15
71 21.5
72 34.8
73 15
74 10
76 18
78 9.75
49 rows selected.
ORDERID QUANTITY
---------- ----------
761 90
LASTORDER
---------
16-DEC-13
45 rows selected.
10 List all customers that are from�the same countries as the suppliers.
12 rows selected.
CUSTOMERID TOTALAMOUNT
---------- -----------
4 1762
5 7612.75
7 450
9 4961.2
11 2828
14 625.2
15 2169
18 424
19 4668
20 20369.93
21 287.8
24 196.2
25 6331.8
28 1836
29 338.2
30 310
32 8891
35 3163.2
37 11998.2
38 998.9
39 11490.7
41 550.8
42 57.5
44 6451.5
45 317.75
46 2280.6
47 264
48 125
28 rows selected.
15 List the number of customers in each country, except the USA, sorted high to
low. Only include countries with 3 or more customers.
COUNT(*) COUNTRY
---------- ---------------
7 France
6 Germany
5 UK
4 Brazil
4 Venezuela
4 Spain
3 Mexico
7 rows selected.
16 List all customer with average orders between $100 and $1200.
CUSTOMERID AVG(TOTALAMOUNT)
---------- ----------------
4 881
7 450
14 625.2
18 424
21 287.8
29 338.2
30 310
38 499.45
41 550.8
45 317.75
46 760.2
47 264
48 125
13 rows selected.
ID FIRSTNAME TOTALAMOUNT
---------- --------------- -----------
1 Maria
2 Ana
3 Antonio
4 Thomas 285
4 Thomas 1477
5 Christina 174.9
5 Christina 630
5 Christina 1031.7
5 Christina 1565.65
5 Christina 4210.5
6 Hanna
7 Fr�d�rique 450
8 Mart�n
9 Laurence 1057
9 Laurence 1820.8
9 Laurence 2083.4
10 Elizabeth
11 Victoria 1328
11 Victoria 1500
12 Patricio
13 Francisco
14 Yang 625.2
15 Pedro 2169
16 Elizabeth
17 Sven
18 Janine 424
19 Ann 655
19 Ann 950
19 Ann 3063
20 Roland 1834.2
20 Roland 3600.73
20 Roland 4813.5
20 Roland 4903.5
20 Roland 5218
21 Aria 287.8
22 Diego
23 Martine
24 Maria 93
24 Maria 103.2
25 Peter 2300.8
25 Peter 4031
26 Carine
27 Paolo
28 Lino 1836
29 Eduardo 338.2
30 Jos� 310
31 Andr�
32 Howard 8891
33 Manuel
34 Mario
35 Carlos 3163.2
36 Yoshi
37 Patricia 1419.8
37 Patricia 1762
37 Patricia 2614.5
37 Patricia 6201.9
38 Helen 240.4
38 Helen 758.5
39 Philip 11490.7
40 Daniel
41 Annette 550.8
42 Yoshi 57.5
43 John
44 Renate 1873.5
44 Renate 2085
44 Renate 2493
45 Jaime 317.75
46 Carlos 510
46 Carlos 720
46 Carlos 1050.6
47 Felipe 264
48 Fran 125
49 Giovanni
50 Catherine
74 rows selected.
18 Match customers that are from the same city and country
13 rows selected.
CUSTOMERID COUNT(*)
---------- ----------
4 2
5 5
7 1
9 3
11 2
14 1
15 1
18 1
19 3
20 5
21 1
24 2
25 2
28 1
29 1
30 1
32 1
35 1
37 4
38 2
39 1
41 1
42 1
44 3
45 1
46 3
47 1
48 1
28 rows selected.
20 Which products were sold by the unit (i.e. quantity = 1)
no rows selected
21 List customers who placed orders that are�larger than the average of each
customer order
CUSTOMERID TOTALAMOUNT
---------- -----------
25 4031
46 1050.6
24 103.2
19 3063
9 1820.8
5 1565.65
44 2493
38 758.5
5 4210.5
37 6201.9
4 1477
9 2083.4
20 4813.5
20 4903.5
11 1500
20 5218
16 rows selected.
SUPPLIERID PRODUCTSPRICE
---------- -------------
4 138
7 177.85
8 112.7
23 Retrieve the customer names in the lower case, their city and country names in
upper case.
50 rows selected.
24 For American customers, count the number of times �A� occurs in their first
names.
25 Write a query to display the products that are not ordered by any customers.
SQL> select productid
2 from orderitem
3 where productid not in(
4 select productid
5 from orderitem, orders
6 where orderid=orders.id);
no rows selected
26 Write a query to display all customer details where customer placed an order
during the year 2013 and in the 4th week of a month.
28 Write an SQL statement to convert the current date to new date picture. ex:
MONDAY 10th 2005 10:30.00 PM
29 Write a query which will return the DAY of the week. (i.e. MONDAY), for any date
entered in the format: DD.MM.YY.
30 Write a query to display details of orders which are placed on last Friday of a
month.
31 Write a query that will display list of products and their unit price and the
comments as follows.
32 If the unitprice is more than 20 then display �EXPENSIVE�
33 If the salary is equal to 20 then display �AVERAGE�
34 If the salary is less than 20 then display �INEXPENSIVE�
35 Write a query to find out the customers who have placed maximum number of
orders.
36 Write a query to find out the year, where most orders were placed. Display the
year and No. of orders.
37 Write a query to retrieve the customer name, total order amount by the customer.
38 Write a query to retrieve the company name detail of the supplier living in the
same city of any of his customers.
39 Find all suppliers who supplied lowest valued products in each category
(Discontinued / Not Discontinued).
40 Retrieve the details of supplier who supplied least number of products during
the year 2013.