Select operation

I have two tables as follows:

i need to a select statement to show the following for each class
class,sum of total,sum of remaining,sum of ammount
thanks to all
sami tarawnehAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
shoudn't you need a student_id in your table: payment?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
or you can try something like this?

select a.class, a.SumOftotal, a.SumOfremaining, b.SumOfammount from

SELECT Students.class, Sum( AS SumOftotal, Sum(Students.remaining) AS SumOfremaining
FROM Students
GROUP BY Students.class
) as a 

inner join

SELECT payments.class, Sum(payments.ammount) AS SumOfammount
FROM payments
GROUP BY payments.class
) as b on a.class = b.class

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pawan KumarDatabase ExpertCommented:
Please try this-

SELECT p.class , SUM( as total , SUM(s.remaining) as remaining , SUM(p.ammount) as ammount
Students as s
INNER JOIN payments as p ON p.class = s.class
GROUP BY p.class

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sami tarawnehAuthor Commented:
thanks alot
thats what i was looking for, except for replacing inner join with left join to get the classes with no payments

thanks again
Pawan KumarDatabase ExpertCommented:
Hey sami, did u try my suggestion ? It will give you the same output.
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:

I think based on your statement above, it may return different (multiply effect) results if there are multiple payments based on the joining conditions.
Pawan KumarDatabase ExpertCommented:

No. It will give the same result as yours.
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
well, check this out, the sample i drafted out the solution...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.