2012-04-10 69 views
0

嗨我試圖總結這些表,我想不出什麼我做錯了SQL語句總和

我的第一個表是:

Reserve 
ReserveID MembershipID PlayerCount Time CourseID 

我的第二個表是

我試圖
Courses 
CourseID Name 

我的SQL語句是在這裏:

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") 
+0

什麼是「錯誤」 - 不會給你你想要的答案(你想要什麼答案?)?給出錯誤(錯誤是什麼)?你想做什麼?增加特定課程的玩家人數? – 2012-04-10 23:40:02

+0

當我填充表格時,我沒有得到正確的總和。 – helloman 2012-04-10 23:52:59

+1

你確定你正在以正確的方式加入嗎? 不應該這樣 'LEFT JOIN課程在Courses.CourseID = Reserve.ReserveID' 更像 'LEFT JOIN課程在Courses.CourseID = Reserve.CourseID'? – fancyPants 2012-04-11 00:18:50

回答

0

您似乎混合了別名。避免它們

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") 
+0

Starx感謝您的回覆,但仍然給我留下不正確的答案 – helloman 2012-04-10 23:53:28