April 10, 2012

SQl Statement Sum

Question by helloman

Hey guys I am trying to sum these tables and I can’t figure out what I’m doing wrong

My first table is:

Reserve
ReserveID   MembershipID   PlayerCount   Time    CourseID

My second table is

Courses
CourseID   Name

My sql statement that I am trying is here:

Select Sum(Reserve.Player_Count)Total
From Reserve 
Left Join Courses 
On Courses.CourseID = Reserve.ReserveID 
Where Time = "2012-04-09 07:10:00" 
And Courses.Name = "Lake" (or I had Courses.CourseId = "1")

Answer by Starx

You seem to mixing alias. Avoid them

Select Sum(Reserve.Player_Count)Total
From Reserve 
Left Join Courses 
On Courses.CourseID = Reserve.ReserveID 
Where Reserve.Time = "2012-04-09 07:10:00" 
--     ^ Right here  
And Courses.Name = "Lake" (or I had Courses.CourseId = "1")

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!