0% found this document useful (0 votes)
42 views

SQL Quiz Sample - C

The document contains a sample SQL quiz with 9 questions about 3 database tables: Baskets, Ingredients, and Contents. The questions involve selecting data from the tables to find ingredient counts, total costs, minimum values, maximum values, and updating or deleting data based on conditions. SQL statements like SELECT, UPDATE, DELETE, COUNT, SUM, GROUP BY, and HAVING are used to query and modify the data.

Uploaded by

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

SQL Quiz Sample - C

The document contains a sample SQL quiz with 9 questions about 3 database tables: Baskets, Ingredients, and Contents. The questions involve selecting data from the tables to find ingredient counts, total costs, minimum values, maximum values, and updating or deleting data based on conditions. SQL statements like SELECT, UPDATE, DELETE, COUNT, SUM, GROUP BY, and HAVING are used to query and modify the data.

Uploaded by

sherin
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Quiz C – Sample

Database Fundamentals
Write SQL statements. For Questions 1 to 5, use the tables

Baskets ( basket, saleprice, numberofbaskets )


e.g. Special basket sells for $20, and there are 35 in stock.

Ingredients ( ingredient, costprice)


e.g. banana costs $2 each

Contents ( basket, ingredient, howmany )


e.g. Special baskets have 5 bananas ( and other ingredients ).

Q1. Find the number of different ingredients in a Special basket.


Select count(ingredient)
From ingredients
Where basket = “special”

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

For Questions 6 to 9, use the tables

likessport ( girl, sport)


e.g. Kim likes tennis ( and other sports )

likesreading( girl, language )


e.g. Kate knows Java ( and other languages ).

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

You might also like