我正在尝试仅在字段prl.attribute1,a.owner_role和b.responder的内容相同时提取记录。我正在使用group by和count函数,但它不起作用。我究竟做错了什么?这是我的代码。
select
b.notification_id,
b.item_key,
b.begin_date,
b.end_date,
replace(b.subject,'"','') as subject,
a.owner_role as initiator,
b.responder as approver,
b.RECIPIENT_ROLE,
b.from_role,
prl.attribute1 reg_num,
c.proxy_role As Responder,
c.action,
sum(case prl.line_type_id
when 1 then -- goods
round(nvl(prl.rate,1) * prl.quantity * prl.unit_price,0)
when 1020 then -- rate based
round(nvl(prl.rate,1) * prl.quantity * prl.unit_price,0)
when 1024 then -- rate based
round(nvl(prl.rate,1) * prl.quantity * prl.unit_price,0)
when 1025 then
round(nvl(prl.rate,1) * prl.quantity * prl.unit_price,0)
when 1021 then -- amount based service
round(nvl(prl.currency_amount,prl.amount) * nvl(prl.rate,1),0)
when 1022 then -- insurance
round(nvl(prl.currency_amount,prl.amount) * nvl(prl.rate,1),0)
when 1023 then -- pf
round(nvl(prl.currency_amount,prl.amount) * nvl(prl.rate,1),0)
end
) req_amount_us
from
apps.po_requisition_lines_all prl
Left join
apps.po_requisition_headers_all prh On prl.requisition_header_id=prh.requisition_header_id
Left Join
wf_items a On prh.requisition_header_id=to_number(substr(a.item_key,1,instr(a.item_key,'-',1)-1))
Left Join
wf_notifications b On substr(a.item_key,1,instr(a.item_key,'-',1))=substr(b.item_key,1,instr(b.item_key,'-',1))
Left Join
wf_comments c On b.notification_id=c.notification_id AND c.action ='RESPOND_WA'
Where 1=1
--and prl.attribute1 = '2017/764570'
and a.item_type = 'REQAPPRV'
and a.root_activity= 'MAIN_REQAPPRV_PROCESS'
and b.begin_date >= '01-JAN-2017'
and b.message_type = 'REQAPPRV'
and b.message_name = 'XXAPPROVAL_NOTIFICATION'
--and b.responder = a.owner_role
group by
b.notification_id, b.begin_date, b.end_date, b.subject, b.item_key, /*a.item_key,*/ a.owner_role, b.responder,b.RECIPIENT_ROLE, b.from_role, prl.attribute1, c.proxy_role, c.action
Having
Count(prl.attribute1) > 1
and Count (a.owner_role) > 1
and Count (b.responder) > 1
Order by prl.attribute1, b.begin_date, b.notification_id