請協助我統計我的查詢返回的行數,以顯示一些員工在特定月份工作的數量。Count DISTINCT Employees
我有我的總時數,模式&員工姓名,但我該如何返回本月工作的員工的確切數量?
Count(DISTINCT LD.Employee)
顯示每個員工發生一次,但是如何添加1以獲得52作爲我的最終答案?
SELECT LD.Period, LD.EmOrg, LD.EmType, LD.Employee,
Sum(LD.RegHrs) AS 'Total Hours', Count(LD.RegHrs) AS 'Mode',
Count(DISTINCT LD.Employee) AS 'Counted Employees'
FROM SSI.dbo.LD LD
GROUP BY LD.Employee, LD.Period, LD.EmOrg, LD.EmType
HAVING (LD.EmOrg Like '%T00') AND (LD.EmType='S')
數據:
Period EmOrg EmType Total Hours Mode Employee Counted Employees
201306 RSA/PZB/T00 S 180 66 GOVINP1 1
201306 RSA/PZB/T00 S 200 35 LANDCJ1 1
201306 RSA/PZB/T00 S 180 34 WOODRE 1
201306 RSA/JNB/T00 S 160 33 MOKOHM1 1
201306 RSA/PLZ/T00 S 160 32 KAPPPJ 1
201306 RSA/PZB/T00 S 187 31 CAHISJ 1
201306 RSA/PZB/T00 S 180 31 ZEMUN 1
201306 RSA/PZB/T00 S 190 28 SAULDD1 1
201306 RSA/DUR/T00 S 188 26 JEROP1 1
201306 RSA/PZB/T00 S 204 24 NGOBS1 1
201306 RSA/PZB/T00 S 201 23 DLAMMP 1
201306 RSA/PZB/T00 S 192 23 ZONDNS2 1
201306 RSA/PLZ/T00 S 160 22 MPHURK 1
201306 RSA/PZB/T00 S 186 21 DUBESE1 1
201306 RSA/PZB/T00 S 187 21 MABAMS 1
201306 RSA/PZB/T00 S 189 21 MBELBV 1
201306 RSA/PZB/T00 S 188 21 MNDAMB 1
201306 RSA/PZB/T00 S 186 21 ZONDIPB1 1
201306 RSA/JNB/T00 S 180 20 BOKAML 1
201306 RSA/PTA/T00 S 180 20 DAVEJA 1
201306 RSA/PZB/T00 S 180 20 DLAMVK 1
201306 RSA/JNB/T00 S 163.5 20 ERLAME 1
201306 RSA/PZB/T00 S 180 20 HLONLA 1
201306 RSA/CPT/T00 S 179 20 HOUGHJ 1
201306 RSA/PZB/T00 S 180 20 KAFFS 1
201306 RSA/PTA/T00 S 180 20 KEYTDJ 1
201306 RSA/JNB/T00 S 180 20 KHATEK 1
201306 RSA/DUR/T00 S 180 20 KHUZB1 1
201306 RSA/PTA/T00 S 180 20 LEHLTJ 1
201306 RSA/JNB/T00 S 180 20 LETSMM2 1
201306 RSA/PTA/T00 S 170 20 MAKGMJ 1
201306 RSA/BDV/T00 S 160 20 MALEVT1 1
201306 RSA/JNB/T00 S 180 20 MAPHV1 1
201306 RSA/JNB/T00 S 180 20 MNGOTX 1
201306 RSA/PZB/T00 S 180 20 MTHETN1 1
201306 RSA/BDV/T00 S 180 20 MULAG1 1
201306 RSA/DUR/T00 S 180 20 NDLOCT1 1
201306 RSA/PZB/T00 S 180 20 NDLOS 1
201306 RSA/BFN/T00 S 180 20 NELL 1
201306 RSA/PLZ/T00 S 180 20 OOSTLC 1
201306 RSA/CPT/T00 S 180 20 PAULDMR 1
201306 RSA/PZB/T00 S 180 20 PHIRSN1 1
201306 RSA/PZB/T00 S 180 20 RAMBD1 1
201306 RSA/PZB/T00 S 180 20 SANLLJ 1
201306 RSA/PZB/T00 S 180 20 SMITEP3 1
201306 RSA/CPT/T00 S 180 20 SOCEGR 1
201306 RSA/PZB/T00 S 180 20 SOKOV 1
201306 RSA/CPT/T00 S 180 20 TSHIJC 1
請編輯和縮進您的帖子,以便更多'易消化'。 – cubitouch
'SELECT COUNT(LD.Employee)'應該給你表中的條目總數,'SELECT COUNT(DISTINCT LD.Employee)'會給你DISTINCT Employees的數量,許多人不管他們有多少班次工作。如果你不希望這兩個數字中的任何一個能夠澄清你的問題。數據集中似乎有48個條目,52是從哪裏來的? –