oncik oncik - 15 days ago 7
SQL Question

Count how many number in a row that have same value

----------------------
| Name | Location_no |
----------------------
| Joe | 1 |
| Dan | 2 |
| Sim | 2 |
| Jon | 3 |
| Jim | 1 |
| Kan | 2 |
| Tim | 2 |
| Doe | 4 |


I wanted to count how many Location Number that have 2 or more people lived.

Example like: Location Number 1 have 2 people lived there.
Location Number 2 have 4 people lived there.

I don't know How to word this question more clear, comment if you need clearer explanation.

Answer
SELECT Location_No, COUNT(*) AS num_lived
FROM yourTable
GROUP BY Location_No
HAVING COUNT(*) > 1
Comments