# 3.7 Assignment

course: Academy — 65-GENAI-for-Engineers
module: Academy/65-GENAI-for-Engineers
type: pdf
source_url: https://personal-learn.armco.dev/files/Academy/65-GENAI-for-Engineers/assignments/3.7_Assignment__Having_Clause/3.7_Assignment.pdf
pages: 1

---
[page 1]
Assignment / Activity: Practice Using HAVING Clause 
 Title: Filtering Grouped Data Based on Aggregates 
 Instructions  : Use  https://sqliteonline.com  or any  SQL IDE to complete the following: 
 Q1. Create a table  students  with the following columns: 
 ●  id  (INTEGER, Primary Key) 
 ●  name  (TEXT) 
 ●  class  (INTEGER) 
 ●  marks  (INTEGER) 
 Insert at least 6–8 records across different classes. 
 Q2. Write a query to calculate the average marks per class using  GROUP BY  . 
 Q3. Modify the query to only show classes with an average mark above 85 using  HAVING  . 
 **Q4. Create another table called  orders  with columns:  city  ,  price  . Insert data for at least 2 
 cities with 3+ orders each. Write a query to show  total revenue per city  using  GROUP BY  . 
 Q5. Now filter and display only those cities where the total revenue exceeds ₹400 using 
 HAVING  .