I’m trying to put together a command to extract the data from different tables and use the count() function but I just can’t get it right.
I need to get the name and description of the service and count() how many times that service was done in X year
my tables:
Services =id_service, description, name
history = id, id_service(it’s a foreign key of services), year
any help would be appreciated 😀
I tried something like this but it does not work :S
select X.description, X.name, Z.year
from Services X
INNER JOIN history Z
ON Z.id_service = x.id_service AND Z.year= 2010;
Close. You need to add your COUNT() command to the field you are counting and add the other fields to the GROUP BY: