Keenan Molver
Keenan Molver

Reputation: 41

Assistance with SELECT and COUNT

I'm trying to write a MySQL query to extract a distinct list of UUID's along with a count of the occurrences. Additionally, these counts needs to be grouped with certain status codes that I pass through in a WHERE clause.

I've tried a combination of GROUP BY and COUNT keywords but I cant seem to get the output I need.

I've tried the following SQL statement but I didn't get the correct results

SELECT DISTINCT distribution_id, count(distribution_id), status_id from outbound where status_id in (52, 41, 42)

The output numbers are incorrect and I don't know what I'm missing in the query. I need a list of the UUID's, the amount of times they occur and what status_id that count relates to.

Upvotes: 3

Views: 50

Answers (1)

undefined_variable
undefined_variable

Reputation: 6218

SELECT distribution_id, count(distribution_id), status_id 
from outbound 
where status_id in (52, 41, 42)
GROUP BY distribution_id,status_id

GROUP BY operation can help..

Upvotes: 3

Related Questions