2012-05-04 151 views
0

嗨快速mysql的問題,香港專業教育學院得到這個當前查詢什麼讓我頭疼MySQL查詢左連接錯誤

SELECT stafflist.id, stafflist.full_name, (wages.wage /5) * stafflist.avgworkingdays AS workingwage , 
count(sick.d) AS DaysOffSick, variables.value AS VAT, count(hols.d) AS Prebooked_Holidays, 


((((wages.wage /5) * stafflist.avgworkingdays)/stafflist.avgworkingdaysmonth)*count(sick.d)) AS daysoffsickvalue, 
((((((wages.wage/5) * stafflist.avgworkingdays) * 3) /100) * (100 + variables.value))/ (stafflist.avgworkingdaysmonth)) * (stafflist.avgworkingdaysmonth 
- count(hols.d)) AS Commision_target_After_Holidays 

from stafflist 

LEFT JOIN wages ON wages.wagesid = stafflist.WageGrade 
LEFT JOIN variables ON variables.company=stafflist.company and variables.name = 'VAT' 
LEFT JOIN off AS sick ON sick.StaffMember = stafflist.id and sick.isitsick=1 AND sick.addedtowages=0 
LEFT JOIN off As hols ON hols.StaffMember = stafflist.id and hols.isitsick=0 AND hols.addedtowages=0 AND hols.m = MONTH(now()) -1 AND hols.prebooked=1 
WHERE stafflist.id = 48 
GROUP By stafflist.full_name 

問題是我希望它算多少天被標記爲病人和多少作爲節假日 然而,一旦我離開再次加入關閉表並將它命名爲hols領域daysoffsick拉標記爲假期的日子

請你幫我這個

問候 巴蒂爾

+3

那麼什麼是...在查詢中的錯誤?我只能看到括號和悲傷。 –

回答

1

嘿slowie從我的理解,你只是想要從病假和按員工分組的預定假日天簡單計數。你需要做的是在你的左連接中放置一個子查詢。我提供了一個簡單的表格,其中包含數據和部分查詢。

http://sqlfiddle.com/#!2/8a73c/13

它給你插入查詢其餘在一起,但我相信這是你所追求的