0

我在 Blackberry 7.0 的应用程序中使用了带有 Group By Clause 的 HSQL 查询。

我尝试了以下查询:

SELECT Cus.cus_id,Cus.cus_last_name,Inv.inv_id,Sum(Inv.inv_due_amt) as ACCOUNT
FROM Customer as Cus,Invoice as Inv
Where Cus.cus_id=Inv.cus_id 
GROUP BY Cus.cus_last_name;

我越来越"Not in aggregate function or group by clause error"

如何解决这个问题?

4

2 回答 2

1

Cus.cus_id 和 Inv.ind_id 列必须位于聚合函数或 GROUP BY 子句中。我怀疑你想要:

SELECT 
  Cus.cus_id,Cus.cus_last_name,Inv.inv_id,Sum(Inv.inv_due_amt) as ACCOUNT 
FROM 
  Customer as Cus,Invoice as Inv 
Where 
  Cus.cus_id=Inv.cus_id 
GROUP BY 
  Cus.cus_last_name, Cus.cus_id, Inv.inv_id

但是我不确定这会给你真正想要的分组。这可能是您想要的更多:

SELECT 
  Cus.cus_id,Cus.cus_last_name,Sum(Inv.inv_due_amt) as ACCOUNT 
FROM 
  Customer as Cus,Invoice as Inv 
Where 
  Cus.cus_id=Inv.cus_id 
GROUP BY 
  Cus.cus_last_name, Cus.cus_id
于 2013-01-08T09:31:12.697 回答
0

所有非聚合列都应该是 GROUP BY 子句的一部分。尝试这个

SELECT Cus.cus_id,Cus.cus_last_name,Inv.inv_id,Sum(Inv.inv_due_amt) as ACCOUNT
FROM Customer as Cus,Invoice as Inv
Where Cus.cus_id=Inv.cus_id 
GROUP BY Cus.cus_id,Cus.cus_last_name,Inv.inv_id
于 2013-01-08T09:31:26.393 回答