我在Blackberry 7.0的应用程序中使用了HSQL查询和Group By Clause。
我尝试了以下查询:
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"
如何解决此问题?
答案 0 :(得分: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
答案 1 :(得分: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