我有一张桌子products
:
id user products
1 user1 product
2 user2 product
3 user1 product
4 user3 product
5 user4 product
现在,我想了解哪个用户拥有最多的产品(user1)
$query = 'SELECT * FROM products WHERE ...';
对mySQLi面向对象查询有任何建议吗?
答案 0 :(得分:2)
您可以这样处理:
SELECT `p`.`user` FROM `products` as p GROUP BY `user` ORDER BY count(id) DESC LIMIT 1