If we have these 2 tables ...:
usuarios
--------
id | nombre_usuario
productos
---------
id_producto | id_usuario | nombre_producto | tipo_producto
.. And we want to know how many products each user has, we could solve it in the following way:
SELECT usuarios.nombre_usuario, COUNT(*)
AS contar FROM usuarios
INNER JOIN productos ON usuarios.ID = productos.id_usuario
GROUP BY productos.id_usuario
If we want to obtain the result of the previous query imagining that the product type is "others", we would add WHERE...
, like this:
SELECT usuarios.nombre_usuario, COUNT(*)
AS contar FROM usuarios
INNER JOIN productos ON usuarios.ID = productos.id_usuario
WHERE tipo_producto = 'otros'
GROUP BY productos.id_usuario
Finally, if we want to create a table with the results of that query, we just have to add CREATE TABLE nombre_de_la_tabla
in front of the query. Greetings and I hope my question-answer is useful.