我希望有人可以帮我解决这个问题。
我正在处理一个需要跟随的查询,
我编写了以下代码来获取Office,SubProgram,ServiceType和Total#Of客户的约会日期在给定的日期范围内且其约会状态为“完成”
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
并编写以下代码以获取Office,SubProgram,ServiceType和客户的总数#,其开始日期在约会日期的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)
答案 0 :(得分:0)
{{1}}