SQL Query to Count Images Associated with Each Product
Unfortunately, the query you provided is not valid SQL syntax. It seems like you are trying to count the number of images associated with each product. Here is a possible query that achieves this:
SELECT p.id, p.name, COUNT(i.id) AS num_images
FROM product p
LEFT JOIN imgs i ON i.f_productId = p.id
GROUP BY p.id, p.name;
This query uses a left join to include all products even if they have no associated images. The COUNT function is used to count the number of non-null image IDs for each product. The results are grouped by product ID and name.
原文地址: https://www.cveoy.top/t/topic/or1R 著作权归作者所有。请勿转载和采集!