我有一个看起来像这两个表:列表包含非聚合列
users:
id int unsigned auto_increment,
primary key(id),
[...]
product:
id int unsigned auto_increment,
seller id int unsigned auto_increment,
primary key(id),
foreign key(seller) references users(id)
[...]
我想拥有的用户提供他们的所有属性和产品的每个用户都有量的列表。我试过如下:
select u.id, [...], count(p.id) from users u, products p where p.seller=u.id and [...]
然而这使我有以下错误:
ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'db.u.id'; this is incompatible with sql_mode=only_full_group_by
什么是实现想要的结果的正确方法?为什么这不起作用?
好吧,通过使用select id作为用户ID(来自id = userid的产品的select count(id)),相对较快地解决了我的第一个问题。我仍然不明白这个错误。 – Addi
错误提到了一组。发帖实际查询你已经试过 – Horaciux
你正在使用哪个dbms? –