嘿伙计们一个快速的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将标记为假期的日子拉出来
你可以帮我解决这个问题吗?
问候 沙恩
答案 0 :(得分:1)
嘿,从我的理解来看,你只需要一个简单的假日计划,以及按员工分组的预定假期。你需要做的是在你的左连接中放置一个子查询。我提供了一个更简单的表格,其中包含您需要的数据和部分查询。
http://sqlfiddle.com/#!2/8a73c/13
由您决定将其余的查询一起插入,但我相信这就是您的目标