Complete the code to group users by their city.
User.group(:[1]).countThe group method groups records by the specified column. Here, grouping by city groups users by their city.
Complete the code to select cities having more than 5 users.
User.group(:city).having('COUNT(*) > [1]').count
The having clause filters groups. Here, it selects cities with more than 5 users.
Fix the error in the code to group orders by status and filter those with total count greater than 2.
Order.group(:status).having('COUNT(*) [1] 2').count
The having clause should use '>' to filter groups with count greater than 2.
Fill both blanks to group products by category and select those with average price less than 100.
Product.group(:[1]).having('AVG(price) [2] 100').count
Grouping by category groups products by their category. The having clause filters groups where the average price is less than 100 using '<'.
Fill all three blanks to group employees by department, select those with max salary greater than 50000, and order by department.
Employee.group(:[1]).having('MAX(salary) [2] [3]').order(:department)
The code groups employees by department. The having clause filters groups where the maximum salary is greater than 50000. Finally, it orders the results by department.
