select max(a.cuiseq) as cuiseq,
  count(distinct a.cuiseq) as cnt
from afr3123 a
where a.ktktcd=:ktktcd
  and a.vseq=:cvseq
  and a.cucd=:cucd
  and a.cuscd=:cuscd
  and a.cls='23' and a.cls1='0' and a.sts in ('0','1') and a.ceslip2='05'
  and (:cuiseq is null or a.cuiseq = :cuiseq)
