안녕하세여 초보개발자인데 쿼리질문합니다.
집계하여 페이징하는 프로시저를 개발중인데
아래쿼리에서 Total_Cnt 값을 구할때 아래처럼 Count 함수를 또 안쓰고는 구할수 있는 방법이있을까요??
성능이 별로 좋지않을까해서요...
select
j.jobid ,
j.start_time,
j.end_Time,
(select count(*) from user_log where jobid=j.jobid) as USR_Cnt,
(select count(*) from email_log where jobid = j.jobid ) as Email_Cnt,
(select count(*) from com_log where jobid = j.jobid ) as Com_Cnt,
(select count(*) from user_log where jobid=j.jobid)+
(select count(*) from email_log where jobid = j.jobid )+
(select count(*) from com_log where jobid = j.jobid ) as Total_Cnt
from Job_hist as J
Order by j.Jobid desc
OFF SET 0 ROWS
FETCH NEXT 10 ROWS ONLY
결과값
JOBID / Start_Time / End_Time / USR_Cnt / Email_Cnt / Com_Cnt / Total_Cnt
457 / 2019-04-05 13:00:00.000 / 2019-04-05 13:00:03.526 / 5 / 3 / 7 / 15
456 / 2019-04-05 12:00:50.000 / 2019-04-05 12:00:53.253 / 2 / 1 / 0 / 3
455 / 2019-04-05 12:00:40.000 / 2019-04-05 12:00:43.132 / 3 / 2 / 4 / 9
454 / 2019-04-05 12:00:30.000 / 2019-04-05 12:00:33.225 / 6 / 9 / 2 / 17
453 / 2019-04-05 12:00:20.000 / 2019-04-05 12:00:23.153 / 3 / 0 / 3 / 6 |