0

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...

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I hoped that the resultset can have additional columns instead of more rows.
@Tobias, could you explain what you mean by that?
If i run this query i get up to 20 rows starting with the same name, what I really need is only one row per name and one col for type and one col per subtype.
0
SELECT name, type, subtype, Count(*) FROM table GROUP BY name, type, subtype

How about that?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.