-1
有2代表在MySQL数据库:计数在产品上市的每个产品订单,一个查询
products: id, ...
products_order: id, pid,
^
products.id
在产品列表网页如何显示每个产品的订单(如该产品由4人命令)而不需要查询每个产品。 例如
select count(*) from products_order where pid = 1
获得的结果是这样的:
pid count
1 5
2 12
3 1
4 32
... ...
至于有我试过
SELECT COUNT(*) FROM products WHERE pid IN (1,2,3,4, ... 20)
,但它并没有给我20有一个什么样的分页我想要。
学习使用'组by'。 –