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?
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 ChongSoftware Team LeadCommented:
shoudn't you need a student_id in your table: payment?
Ryan ChongSoftware Team LeadCommented:
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

Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

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 ChongSoftware Team LeadCommented:

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 ChongSoftware Team LeadCommented:
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.