July 14, 2010 at 8:02 am
I have a table Below ...
Name DOB MathsScienceChemistyPhysics
RAM 11/2/1986 00 0 45
RAM 12/5/1985 25 0 0 0
ANTHONY07/6/1981 250 0 0
RAM 11/2/1986 250 0 0
RAM 11/2/1986 00 85 0
ANTHONY07/6/1981 050 0 0
ANTHONY07/6/1981 00 75 0
I want the result as
Name DOB MathsScienceChemistyPhysics Total
RAM 11/2/1986 25 0 85 45 155
Anthony 07/6/1981 25 50 75 0 150
July 14, 2010 at 8:19 am
looks like school homework to me, therefore no solution but a guide:
Read about using aggregate functions in SQL, in your case it would be SUM.
Also, please click the link in my signature to learn how to post your question in forum's polite way.
July 14, 2010 at 11:58 pm
Also, since you're new, please study the article at the first link in my signature line below. People will trip over each other to help you if you do what the article says.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 15, 2010 at 4:52 am
Hello dheer,
Please thy the following select query
select
name,
MAX(dob), MAX(maths), MAX(science), MAX(chemisty), MAX(physics),
MAX(maths) + MAX(science) + MAX(chemisty) + MAX(physics)
from lessons
group by name
I hope that helps you
July 15, 2010 at 1:59 pm
Eralper (7/15/2010)
Hello dheer,Please thy the following select query
select
name,
MAX(dob), MAX(maths), MAX(science), MAX(chemisty), MAX(physics),
MAX(maths) + MAX(science) + MAX(chemisty) + MAX(physics)
from lessons
group by name
I hope that helps you
The problem with that is if there is more than one entry for any given subject. And, yeah... I know... the OP provided no such data but it will happen and the OP needs to be ready for it.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 15, 2010 at 11:32 pm
Hi Jeff,
Actually the sample data provided has more than one record for RAM and for Maths
It is not explicitly stated but, I chosed using MAX perhaps and AVG could be better.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply