Professional Documents
Culture Documents
University of Technology Sydney SQL Summary Notes For SQL Test 2024
University of Technology Sydney SQL Summary Notes For SQL Test 2024
1. List pizzas with the substring 'i' anywhere within the pizza name.
2. Give the average price of pizzas from each country of origin. Change the column name related to
average price to "average".
select country, avg(price) as average from menu where country is not null group by country
3. Give the average price of pizzas from each country of origin, do not list countries with only one pizza.
select country, avg(price) from menu where country is not null and country = 'italy' group by country
4. List all ingredients and their types for the 'margarita' pizza. Do not use a subquery.
select ingredient, type from items natural join recipe natural join menu where pizza = 'margarita'
5. Give pizzas and prices for pizzas that are more expensive than all Italian pizzas.
select pizza, price from menu where price >any(select max(price) from menu where country = 'italy')
6. Give all pizzas that originate from the same country as the 'siciliano' pizza. Do not include 'siciliano'
pizza in your result table.
select pizza from menu where country in (select country from menu where pizza = 'siciliano') and
pizza != 'siciliano'
7. List each ingredient and the pizza that contains the largest amount of this ingredient.
from recipe
inner join
from recipe
PQ2
1. List all pizzas, giving pizza name, price and country of origin where the country of origin has NOT been
recorded (i.e. is missing).
select pizza, price, country from menu where country is null-- Type query below
2. Give the most expensive pizza price from each country of origin. Sort your results by country in
ascending order.
select country, max(price) as most from menu where country is not null group by country
3. Give the average price of pizzas from each country of origin, only list countries with 'i' in the country's
name. Sort your results based on country in ascending order.
select country, avg(price) from menu where country like '%i%' and country is not null group by
country-- Type query below
4. List all 'fish' ingredients used in pizzas, also list the pizza names. Do not use a subquery.
select ingredient, pizza from items natural join recipe natural join menu where type = 'fish'
5. List all ingredients for the Mexican pizza (i.e. country = 'mexico'). You must use a subquery.
select distinct(ingredient) from recipe where pizza IN (select pizza from menu where country =
'mexico');
6. List all pizzas that cost more than 'stagiony' pizza, also give their prices.
select pizza, price from menu where price >any(select max(price) from menu where pizza =
'stagiony')
7. List ingredients used in more than one pizza. Sort your results in ascending order.
select ingredient from recipe group by ingredient, ingredient having count(pizza) > 1 order by 1
PQ3
1. List all price categories recorded in the MENU table, eliminating duplicates.
2. Give the cheapest pizzas from each country of origin. Sort your results by country in ascending order.
select country, min(price) as least from menu where country is not null group by country order by 1
3. Give cheapest price of pizzas from each country of origin, only list countries with cheapest price of less
than $7.00
select country, min(price) as min from menu where country is not null group by country having
min(price) < 7 order by 1
4. List all 'meat' ingredients used in pizzas, also list the pizza names. Do not use a subquery.
select ingredient, pizza from items natural join recipe natural join menu where type = 'meat'
5. List pizzas with at least one 'meat' ingredient.You must use a subquery.
select distinct(pizza) from items natural join recipe natural join menu where type = 'meat'
6. List all pizzas that cost less than 'siciliano' pizza, also give their prices.
select pizza, price from menu where price <any(select max(price) from menu where pizza =
'siciliano')
7. List the ingredients, and for each ingredient, also list the pizza that contains the largest amount of this
ingredient.
from recipe
inner join
from recipe
SQL TEST
3. What is the smallest section number used in the first semester of 2008
4. How many students are enrolled in Section 2714 in the first semester of 2008?
Select registration.studentid, registration.sectionno from registration where registration.sectionno
= 2714
5. Which faculty members have qualified to teach a course since 1993? List the faculty ID,
course and date of qualifaction.
6. List all students who have a mark in subject ‘41116’ between 60 and 70. Show their student
number and mark and sort the data by marks in descending order.
SELECT sname
WHERE e.sno=s.sno
AND e.subo='41116'
7. Give the subject number, and the number of students who have failed the subject (mark <
50) as ‘no_failing’. Sort the data in subject number order.
FROM enroll
WHERE mark< 50
GROUP BY subno
8. Show student number, and their average mark as ‘amark’ for each student. Only list students
who are enrolled in 4 subjects. List the results in student number order.
FROM enroll
HAVING COUNT(subno) =4
GROUP BY sno
9. List student number, telephone number and mark for students enrolled in subject 30008
with a mark higher than 84. Sort the results by mark (descending) and then by student
number.
WHERE s.sno=e.sno
10. List Subject number and name for subjects which have an average mark that is higher than
75. List the results in descending subject number order.
select subno,avg(mark) from enroll group by subno having count(sno)>2 order by subno desc;
12. Give the subject number, and the highest mark for each subject (as ‘highest_mark’). Only
consider the marks of students with the number ‘1’in their IDs. List the results in subject
number order.
select subno,max(mark) as 'Highest_mark'
from subject where sno like '%1%'
group by subno
order by subno;