0
我希望有人能幫我解決此問題。根據日期範圍查找並計算員工
我在這需要以下結果查詢工作,
- 辦公室,
- 子程序,
- 服務類型,
- 總#的客戶,其預約日期落在給定的範圍之間 約會狀態爲「已完成」,
- 開始日期在約會5日內的客戶總數 約會
我寫了下面的代碼來獲取Office,子程序,服務類型和總#的客戶,其預約日期指定日期範圍內,其預約狀態爲「已完成」
SELECT
fa.new_sitename AS Office
,fs.new_subprogramname AS Subprogram
,Fsrv.NAME AS Servicetype
,COUNT(fa.new_clientidname) AS Total#OfClients
FROM
Firstappointment fa
INNER JOIN
FirstServiceAppointment fs
ON
fa.new_appointment id = fs.new_appointment lookup
INNER JOIN
FirstService Fsrv
ON
fa.new_service = Fsrv.serviceid
WHERE
fs.new_visittypename LIKE 'First'
AND fs.statuscodename LIKE 'done'
AND fa.createdon BETWEEN '05/18/2016' AND '05/30/2016'
GROUP BY
fa.new_sitename
,fs.new_subprogramname
,Fsrv.NAME
並且寫了下面的代碼獲取辦公室,子程序,服務類型和總#客戶的開始日期內預約日期爲5天現在
SELECT
COUNT(fa.new_clientidname) AS "Total # of Clients receiving FV within 5 days"
,fa.new_sitename AS Office
,fs.new_subprogramname AS Subprogram
,Fsrv.NAME AS Servicetype
FROM
Firstappointment fa
INNER JOIN
FirstServiceAppointment fs
ON
fa.new_appointmentid = fs.new_appointmentlookup
INNER JOIN
FirstService Fsrv
ON
fa.new_service = Fsrv.serviceid
WHERE
fs.new_visittypename LIKE 'first'
AND fs.statuscodename LIKE 'done'
AND fa.createdon BETWEEN '05/18/2016' AND '05/30/2016'
AND DATEDIFF(DAY, cast(fa.createdon AS DATE), cast(fs.scheduledstart AS DATE)) <= 5
GROUP BY
fa.new_sitename
,fs.new_subprogramname
,Fsrv.NAME
,如何將這兩個結果集合合併成一個,並使其東西像
Office, Subprogram, ServiceType, Total#OfClients (From First Query), Total # of Clients receiving FV within 5 days" (From Second Query)