Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 2 张桌子 -product和product_features.
product
product_features
我需要抓取所有产品并显示它们的每个功能数量。请帮忙。
尝试这个
SELECT p.id, COUNT( pf.id ) FROM prod p LEFT JOIN prod_feat pf ON p.id = pf.prod_id GROUP BY p.id
如果只需要产品id,则不需要加入:
select pf.prod_id, count(*) as NumFeatures from prod_feat pf group by pf.prod_id