0% found this document useful (0 votes)
6 views6 pages

Previous Final Sub Queries

The document contains a series of SQL queries designed to extract specific information from a database related to sellers, invoices, and student competitions. Key queries include finding sellers with high sales, identifying the most sold onion type, and counting student registrations for competitions. Additionally, it includes subqueries to compare ages and filter results based on specific criteria.

Uploaded by

gasib29798
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Previous Final Sub Queries

The document contains a series of SQL queries designed to extract specific information from a database related to sellers, invoices, and student competitions. Key queries include finding sellers with high sales, identifying the most sold onion type, and counting student registrations for competitions. Additionally, it includes subqueries to compare ages and filter results based on specific criteria.

Uploaded by

gasib29798
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Find the seller name whose sold quantity is more than any seller who sold on 11th
December 2022.

Ans: SELECT Name


FROM Seller
WHERE QtyKG > (
SELECT MAX(QtyKG)
FROM Invoice
WHERE Date = '11 Dec 2022'
);

2. Find the onion type which is sold the most.

Ans: SELECT OnionType


FROM Invoice
GROUP BY OnionType
ORDER BY SUM(QtyKG) DESC
LIMIT 1;

3. Find the sellers who sold on 11th December 2019.

Ans: SELECT Name


FROM Seller
JOIN Invoice ON Seller.SellerID = Invoice.SellerID
WHERE Date = '11 Dec 2019';

4. Show the name of the seller who sells Indian onions.

Ans: SELECT Name


FROM Seller
JOIN Invoice ON Seller.SellerID = Invoice.SellerID
WHERE OnionType = 'India';

5. Find the onion which has the highest price.

Ans: SELECT OnionType


FROM Invoice
ORDER BY Price DESC
LIMIT 1;

6. Show the total price of each type of onion that was sold.

Ans: SELECT OnionType, SUM(Price * QtyKG) AS TotalPrice


FROM Invoice
GROUP BY OnionType;

7. Find the store ID where more than one employee works.

Ans: SELECT StoreID


FROM Seller
GROUP BY StoreID
HAVING COUNT(Name) > 1;

8. Find the seller name and ID whose name starts with "K".

Ans: SELECT Name, SellerID


FROM Seller
WHERE Name LIKE 'K%';
9. Find the invoice info whose price is between 40 and 190.

Ans: SELECT *
FROM Invoice
WHERE Price BETWEEN 40 AND 190;

10. Find the sellers whose name contains "a" in the 3rd position.

Ans: SELECT Name


FROM Seller
WHERE Name LIKE '__a%';

Table 2
a. Find the number of students who registered on 15th February 2022.

Ans: SELECT COUNT(*) AS NumberOfRegistrations


FROM Competition
WHERE RegistrationDate = '2022-02-15';

b. Find the student names of those whose ages are more than the highest age (using
subquery).

Ans: SELECT Name


FROM Student
WHERE Age > (
SELECT MAX(Age)
FROM Student
);

c. Find the number of students who registered for the "Mobile App" competition.

Ans: SELECT COUNT(DISTINCT StudentID) AS NumberOfMobileAppRegistrations


FROM Competition
WHERE CompetitionType = 'Mobile App';

d. Find the total registration fee collected for each competition.

Ans: SELECT CompetitionType, SUM(RegistrationFee) AS TotalFeeCollected


FROM Competition
GROUP BY CompetitionType;

e. Find the student IDs of students whose names start with "N".

Ans: SELECT StudentID


FROM Student
WHERE Name LIKE 'N%';

f. Find the addresses of students who participate in the robotics competition (using
subquery).

Ans: SELECT Address


FROM Student
WHERE StudentID IN (
SELECT StudentID
FROM Competition
WHERE CompetitionType = 'Robotics Competition'
);

g. Find the names of students whose age is greater than any age of the student who lives
in Mirpur (using subquery).

Ans: SELECT Name


FROM Student
WHERE Age > (
SELECT MAX(Age)
FROM Student
WHERE Address = 'Mirpur'
);

-- h. Find the addresses of students who participate in the robotics competition (using
subquery).
SELECT Address
FROM Student
WHERE StudentID IN (
SELECT StudentID
FROM Competition
WHERE CompetitionType = 'Robotics Competition'
);

-- i. Find the names of students whose age is greater than any age of the student who lives in
Mirpur (using subquery).
SELECT Name
FROM Student
WHERE Age > (
SELECT MAX(Age)
FROM Student
WHERE Address = 'Mirpur'
);

You might also like