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