我是数据库方面的新手。我需要总结两列,我还需要从特定列中获取数据。所以我写了这样一个查询:
select orderid,sum(productid),sum(price) from orderdetails
但这会返回错误说明
not a single-group group function
请指导我们。
答案 0 :(得分:1)
您必须添加group by
声明:
select orderid,sum(productid),sum(price) from orderdetails group by orderid
答案 1 :(得分:1)
像这样:如果你这样做,你不能简单地选择一个带有其他聚合函数调用的列 真的很想要,然后你需要使用聚合函数 列(
orderid
)也是,或者您需要放置该特定列 (orderid
)group by
中的select max(orderid),sum(productid),sum(price) from orderdetails
。
select orderid,sum(productid),sum(price) from orderdetails group by orderid
或
{{1}}
请参阅here其他聚合函数。
答案 2 :(得分:1)
select orderid,sum(productid),sum(price) from orderdetails group by orderid
无论何时使用aaggregate函数并且想要选择某些列,只需将所有列放在聚合函数之前,然后将列添加到该列