and a.receipt_key = #{receiptKey}
and a.receipt_num like '%'||#{receiptNum}||'%'
and a.wrt_user_nm like '%'||#{wrtUserNm}||'%'
and a.wrt_organ = #{wrtOrgan}
and c.report_date >= #{startDate}::date
and c.report_date <= #{endDate}::date+1
and c.wrt_dt >= #{startDate}::date
and c.wrt_dt <= #{endDate}::date+1
and a.wrt_organ in
#{organCd}
select a.receipt_key,
a.receipt_num ,
a.wrt_organ ,
a.wrt_part ,
a.wrt_user_seq ,
a.wrt_user_grd ,
a.wrt_user_nm ,
b.reportCnt,
c.case_type ,
c.case_num ,
c.title,
c.report_date ,
c.wrt_dt,
c.status,
d.suspectCnt,
e.name as suspectNm
from activity_case a
inner join (
select receipt_key,
count(*) as reportCnt,
max(case_key) as case_key
from activity_case_info
group by receipt_key
) b on a.receipt_key = b.receipt_key
inner join activity_case_info c
on c.case_key = b.case_key
inner join (
select receipt_key,
count(*) as suspectCnt,
min(suspect_seq) as suspect_seq
from activity_case_suspect
group by receipt_key
) d on a.receipt_key = d.receipt_key
inner join activity_case_suspect e
on a.receipt_key = e.receipt_key and d.suspect_seq = e.suspect_seq
order by c.wrt_dt desc
limit #{rowCnt} offset #{firstIndex}
select count(*)
from activity_case a
inner join (
select receipt_key,
count(*) as reportCnt,
max(case_key) as case_key
from activity_case_info
group by receipt_key
) b on a.receipt_key = b.receipt_key
inner join activity_case_info c
on c.case_key = b.case_key
inner join (
select receipt_key,
count(*) as suspectCnt,
min(suspect_seq) as suspect_seq
from activity_case_suspect
group by receipt_key
) d on a.receipt_key = d.receipt_key
inner join activity_case_suspect e
on a.receipt_key = e.receipt_key and d.suspect_seq = e.suspect_seq
select a.receipt_key,
a.receipt_num ,
a.wrt_organ ,
a.wrt_part ,
a.wrt_user_seq ,
a.wrt_user_grd ,
a.wrt_user_nm ,
b.case_key ,
b.case_num ,
b.report_date ,
b.case_type ,
b.title,
b.wrt_dt,
b.status,
c.apprvCnt,
c.allCnt,
d.fileCnt
from activity_case a
inner join activity_case_info b
on a.receipt_key = b.receipt_key
left outer join (
select case_key,
count(apprv_yn = 'Y' or apprv_yn = 'N') as apprvCnt,
count(*) as allCnt
from activity_case_apprv
group by case_key
) c on b.case_key = c.case_key
left outer join (
select case_key,
count(*) as fileCnt
from activity_case_file
group by case_key
) d on b.case_key = d.case_key
where a.receipt_key = #{receiptKey}
order by b.wrt_dt asc
select count(*)+1
from activity_case
where receipt_num like #{year}||'%'
select count(*)+1
from activity_case a
inner join activity_case_info b
on a.receipt_key = b.receipt_key
where a.receipt_num = #{receiptNum}
and b.case_num like #{year}||'%'