Rumah > Soal Jawab > teks badan
Senarai lajur dalam Jadual 1: Plan_ID, Claim_id, Patient_id, B_OR_G
Senarai lajur dalam Jadual 2: Ojid, Shapland
select distinct a.Plan_ID , a.Total_Claims , Total_Patients , b.PERIOD , b.ORGID,a.B_OR_G FROM (Select distinct Plan_ID , count(distinct Claim_id) as Total_Claims , count(distinct Patient_id) as Total_Patients from table1 group by 1) a JOIN (select * , row_number() over (partition by ORGID,SHAPLANID order by PROCESSINGDATE desc) as rank from table2 qualify rank = 1) b ON LTRIM(a.PLAN_ID, '0') = b.SHAPLANID
Dalam pertanyaan di atas, saya ingin mengekstrak satu lagi lajur bernama "B_or_G" daripada jadual1 (iaitu a) tanpa mengganggu kumpulan mengikut klausa kerana ia perlu mengikut keperluan kami.
Adakah cara yang lebih baik untuk melakukan ini? Terima kasih! !
P粉4477850312024-04-02 00:19:32
Saya rasa anda boleh menggunakan ANY_VALUE(B_or_G)
Contohnya:
select distinct a.Plan_ID , a.Total_Claims , Total_Patients , b.PERIOD , b.ORGID,a.B_OR_G FROM (Select distinct Plan_ID , count(distinct Claim_id) as Total_Claims , count(distinct Patient_id) as Total_Patients , ANY_VALUE(B_OR_G) from table1 group by 1) a JOIN (select * , row_number() over (partition by ORGID,SHAPLANID order by PROCESSINGDATE desc) as rank from table2 qualify rank = 1) b ON LTRIM(a.PLAN_ID, '0') = b.SHAPLANID