0

I tried to retrieve values from 2 tables (main (accounts), sub(account_Details)), which they are: acc_ID,acc_Name,acc_Place,acc_Date, total "total of debts-payment-returned". and i do it like this is below, but an error appear: "You tried to execute a query that does not include the specified expression acc_Name as part of an aggregate function. "

The Code:

select a.acc_ID,a.acc_Name,a.acc_Place,a.acc_Date, sum(b.acc_Sub_Debt)-sum(b.acc_Sub_Payment)+sum(b.acc_Sub_Returned) total from accounts a,account_Details b where a.acc_ID = b.acc_Sub_ID and total < 1000 group by a.acc_ID order by a.acc_ID asc 

1 Answer 1

1

You are selecting bunch of non aggregate columns and you have added only only one column in group by.

Add all the non aggregate columns in group by

select a.acc_ID,a.acc_Name,a.acc_Place,a.acc_Date, sum(b.acc_Sub_Debt)-sum(b.acc_Sub_Payment)+sum(b.acc_Sub_Returned) total from accounts a,account_Details b where a.acc_ID = b.acc_Sub_ID and total < 1000 group by a.acc_ID,a.acc_Name,a.acc_Place,a.acc_Date order by a.acc_ID asc 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.