Reputation: 135
I have this table layout:
uuid bigint(20) unsigned primary auto_increment
timestamp int(11) unsigned
name varchar(255)
type enum('A','B')
subtype varchar(255)
And I'm stuck on the query, what I currently use is this:
SELECT name, COUNT(*) as count FROM table GROUP BY name
After this I'm running a loop for each 'name' to get the amount of entries with type 'B' and then again for each subtype. But this end up in about 500k querys and thats too much, there must be an easier way to do this, but I'm really new to this database stuff...
Upvotes: 0
Views: 80
Reputation: 4519
SELECT name, type, subtype, Count(*) FROM table GROUP BY name, type, subtype
How about that?
Upvotes: 0
Reputation: 2018
You can use multiple values in GROUP BY
.
SELECT name, type, subtype, COUNT(*) as count FROM table GROUP BY name, type, subtype
The result then contains one row for each name, type, subtype combination in the database with the corresponding number of entries.
Upvotes: 2