Avatar of sami tarawneh
sami tarawneh
 asked on

Select operation

I have two tables as follows:
Students
                 id,name,class,total,remaining
payments
                id,st_name,ammount,class

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
Microsoft AccessSQL

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
Ryan Chong

shoudn't you need a student_id in your table: payment?
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pawan Kumar

Please try this-

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

Open in new window

sami tarawneh

ASKER
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Pawan Kumar

Hey sami, did u try my suggestion ? It will give you the same output.
Ryan Chong

@Pawan,

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 Kumar

@Ryan

No. It will give the same result as yours.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ryan Chong

well, check this out, the sample i drafted out the solution...
29065405.accdb