有没有一种方法可以让我编写这个查询,以便将我的子查询的结果与我的category_id
.
SELECT category_id,
count(id) as TOTAL COUNT,
(select count(*) from products where product_path LIKE '%Electronics%'
and category_id = category_id ) as ELECTRONIC COUNT
FROM products
WHERE product_path LIKE '%Products%'
GROUP BY category_id
我想要以下方式的结果:
"category_id" "TOTAL COUNT" "ELECTRONIC COUNT"
"173" "1" "243"
"42" "1" "243"
"211" "41" "243"
"162" "10" "243"
"172" "139" "243"
"116" "54" "243"
"10" "3" "243"
我希望电子计数取决于类别。即,第一行应该是 where category_id = 173
,第二行应该是 where category_id = 42
,第三行应该是 wherecategory_id = 211
等等。