简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM