SQL Quiz Sample - C
SQL Quiz Sample - C
Database Fundamentals
Write SQL statements. For Questions 1 to 5, use the tables
Q2. Find the total cost price of a particular basket, entered by the
user.
Select basket, sum(costprice*howmany)
From ingredients I , contents c
Where i.ingredients = c.ingredients
And basket = [please enter basket name]
Group by basket;
Q3. Which basket has the lowest numberofbaskets, and what is this
number?
Select numberofbaskets
From baskets
Where numberofbaskets <= all (select numberofbaskets from baskets)
Or
Select numberofbaskets
From baskets
Where numberofbaskets <= (select numberofbaskets from baskets)
Q4. What is the highest cost price of an ingredient, and what is the
ingredient and the price ?
Select ingredient, costprice
From ingredients
300418 1|Page
SQL Quiz C – Sample
Database Fundamentals
Where costprice >= all (select costprice from ingredients)
Q5. Change the data in the baskets table so that the sale price is
increased by 10% for all baskets which are above the average
sales price.
Update baskets
Set saleprice = saleprice + saleprice*0.1
Having saleprice > (select avg(saleprice) from baskets)
300418 2|Page
SQL Quiz C – Sample
Database Fundamentals
Q6. Find the number of girls who like each language. Display with the
largest number first.
Select count(girl), language
From likesreading
Group by language
Order by 1 desc,2;
Q7. Display the girls who like tennis and who know the language
C++.
Select ls.girl
From likessport ls, likesreading lr
Where sport = ‘tennis’ and language = ‘c++’
And ls.girl = lr.girl
Q8. Find the girl, and the number of sports liked, by the girl who likes
the largest number of sports.
Select girl, count(sport)
From likessport
Group by girl
Having count(sport) >= all (select count(sport) from likessport
group by girl)
Q9. Girls who know Java are not allowed to like football. Change the
tables.
Delete from likessport
Where sport = ‘footbal’
And girl in (select girl from likesreading where language = ‘java’);
300418 3|Page