我有一個表名Emp_mon_day
其中包括員工目前和缺席的細節。計算天存在和不存在表
我要的是
我需要爲這9名員工,大約目前天與日缺席從Emp_mon_day
表中每個員工的信息合併到下面的查詢
QUERY
SELECT e.comp_mkey,
e.status,
e.resig_date,
dt_of_leave,
e.emp_name,
e.date_of_joining,
e.emp_card_no,
a.pl_days,
pl_days_opening,
a.month1,
a.month2,
a.month3,
a.month4,
a.month5,
a.month6,
a.month7,
a.month8,
a.month9,
a.month10,
a.month11,
a.month12,
a.month1 + a.month2 + a.month3 + a.month4 + a.month5 + a.month6 + a.month7 + a.month8 + a.month9 + +a.month10 + a.month11 + a.month12 AS pl_sum
FROM p_leave_allocation AS a
INNER JOIN
emp_mst AS e
ON a.emp_card_no = e.emp_card_no
WHERE a.year = 2016
AND (datediff(MONTH, e.date_of_joining, CONVERT (DATETIME, getdate(), 103)) >= 6
AND datediff(MONTH, e.date_of_joining, CONVERT (DATETIME, getdate(), 103)) <= 36)
AND (e.resig_date IS NULL
OR (e.dt_of_leave IS NOT NULL
AND e.dt_of_leave >= CONVERT (DATETIME, getdate(), 103)))
AND e.status IN ('A', 'S')
AND e.comp_mkey IN (7, 110)
AND a.Year = 2016;
以上查詢爲我提供的數據如下
[![圖像數據] [1] [1]
爲Emp_mon_day
列細節低於
[![在這裏輸入的形象描述] [2] [2]
什麼必須在輸出格式?你想重複所有天的這9條記錄 – DhruvJoshi
@DhruvJoshi:Naah,看到目前的這些僱員的計算,缺席我想合併,在這個查詢 – BNN
在這種情況下,你要計算現/缺席日 – DhruvJoshi