我創建了一個查詢,它提供了兩列。一個是組織ID,另一個是人員ID。現在我想要檢索那些返回多個人員ID的組織。在Oracle SQL查詢中使用count
我如何可以通過使用計數THT這可以被檢索
查詢修改我下面的查詢: -
select papf.person_id person_id,
hoi.organization_id
From hr_organization_information hoi
,per_all_people_f papf
where hoi.org_information2 = papf.person_id
And hoi.organization_id = 400
and sysdate between papf.effective_start_date and papf.effective_end_date
group by person_id,organization_id
輸出
Person_id organization_id
123 400
678 400
所以現在我怎麼能在這樣的申請數量在上面的查詢中可以使用count(*)> 1的方式嗎?這個organization_id將被提取
select count(PERSON_ID)
FROM (
select papf.person_id person_id,
hoi.organization_id
From hr_organization_information hoi
,per_all_people_f papf
where hoi.org_information2 = papf.person_id
And hoi.organization_id = 400
and sysdate between papf.effective_start_date and papf.effective_end_date
group by person_id,organization_id
-- having count(*)>1
)
我試過上面給出的查詢。但我無法使用它。這也只是返回計數。我也需要檢索organization_id。
很高興看到有人知道存在「distinct」關鍵字的同義詞。 :)但我認爲這個查詢會給出錯誤。雖然'having'可以在沒有'group by'子句的情況下使用,但是必須在選擇列表中有聚合,而不是有序列,即使帶有「唯一」前綴。 –