Hi @Hellothere8028 ,
Please refer to below and check whether it is helpful:
;with cte as (
select cast(completed as date) completeddate ,iscode
,iif(iscode=1,datediff(minute,assigneddate,codeddate),0) codeddatetime
,iif(iscode=0,datediff(minute,assigneddate,qaeddate),0) qaeddatetime
,datediff(minute,assigneddate,completed) overall from
(select *,iif(qaeddate='1900-01-01 00:00:00.0000000',1,0) iscode from ##input)a )
select completeddate
,sum(iif(iscode=1,1,0)) noofvisitbillscoded
,sum(iif(iscode=1,0,1)) noofvisitbillscodedandqaed
,count(1) totalvisitbillscompleted
,cast(sum(codeddatetime)/sum(iif(iscode=1,1,0)) as float)/60 averagetimeforcodedvisitbills
,cast(sum(qaeddatetime)/sum(iif(iscode=1,0,1)) as float)/60 averagetimeforcodedandqaedvisitbills
,cast(sum(overall)/count(1) as float)/60 overallaveragetime
from cte
group by completeddate
Output:
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.