Americo
Americo

Reputation: 919

SQL - Get a count from a single table based on certain column criteria

I need to get a "simple" count of users that have >5 accounts tagged to the same UUID.

To do this for one single UUID, I perform the easy query:

Select count(user) 
From Ply 
Where Uuid Like 'i~cfe3a1eba3c2469aa3695e34c840fb62cb3e8791%'

(I added the % marker because we append extra tags to multiple accounts under the same UUID)

The result in the above query is a result of 5.

To take this to the next level, I want to count the number of users in the entire Ply table who have >5 accounts for 1 UUID.

Any suggestions would be much appreciated!

Upvotes: 0

Views: 413

Answers (1)

Justin Cave
Justin Cave

Reputation: 231651

It sounds like you want

SELECT substr(uuid,1,42), count(user)
  FROM ply
 GROUP BY substr(uuid,1,42)
HAVING COUNT(*) > 5

If that is not what you want, it would be very helpful if you could post a table definition (DDL), some sample data (DML), and the output you want.

Upvotes: 3

Related Questions