0

嘿,伙计们,一个快速的 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 拉出标记为假期的日期

你能帮我解决这个问题吗

问候谢恩

4

1 回答 1

1

嘿,慢下来,据我了解,您只需要简单地计算生病的天数和按员工分组的预定假期的天数。您需要做的是在左连接中放置一个子查询。我提供了一个更简单的表格,其中包含您需要的数据和部分查询。

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

您可以将其余的查询插入在一起,但我相信这就是您所追求的

于 2012-05-04T23:13:15.453 回答