按另一个表的条件获取连接的表的行数


Getting number of rows of joined table by condition on another

>我有两个表产品和products_to_categories

产品信息 - product_id - 名称 - 价格(有多个产品)products_to_categories包含 - product_id - category_id

我所需要的只是在条件为时选择的行数

  1. 仅 ID 为"1"(category_id = "1")的类别;
  2. 仅限价格大于 100 的产品(价格> 100)

有什么想法吗?

select 
p.product_id,
p.name,
p.price
from products p
inner join products_to_categories  pc on pc.product_id = p.product_id
where 
pc.category_id = 1
AND p.price > 100