Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Condition based on COUNT(*) in query with GROUP BY clause

Tags:

sql

group-by

I'm given a table Employee with 300,000 records that contains the following fields:

  • First_name
  • Last_Name
  • Age
  • Location_Id

Query should return location_id values that have more than 75000 records with their count.

like image 579
Prathiba Sundararaj Avatar asked Dec 12 '25 01:12

Prathiba Sundararaj


1 Answers

This is the query you're looking for:

SELECT T.Location_Id
     ,COUNT(T.Location_Id) AS [nbRecords]
FROM yourTable T
GROUP BY T.Location_Id
HAVING COUNT(T.Location_Id) > 75000

Hope this will help you.

like image 83
Joël Salamin Avatar answered Dec 13 '25 15:12

Joël Salamin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!