I have a scenario to get the record in a round-robin way. My table is similar below
Account | Rank | Country | |
---|---|---|---|
Account_A | abc@account_a.com | 1 | USA |
Account_A | cde@account_a.com | 2 | USA |
Account_A | fgh@account_a.com | 3 | USA |
Account_A | klh@account_a.com | 4 | USA |
Account_B | abc@account_b.com | 1 | JAPAN |
Account_C | xyz@account_c.com | 1 | INDIA |
Account_C | pqr@account_c.com | 2 | INDIA |
Account_D | efg@account_d.com | 1 | CHINA |
Account_D | xyz@account_d.com | 2 | CHINA |
Account_E | abc@account_E.com | 1 | JAPAN |
Expected output: I would need to bring only 8 Records per run. I must bring at least one email from each count. There is a possibility some account can have more than 100 records and some has only 1 record. As you can see the sample output below- One contact from each account from A to E ( total five) then an additional record I need to bring from Rank level 2 `( A, C, & D)
Account | Country | |
---|---|---|
Account_A | abc@account_a.com | USA |
Account_A | cde@account_a.com | USA |
Account_B | abc@account_b.com | JAPAN |
Account_C | xyz@account_c.com | INDIA |
Account_C | pqr@account_c.com | INDIA |
Account_D | efg@account_c.com | CHINA |
Account_D | xyz@account_d.com | CHINA |
Account_E | abc@account_e.com | JAPAN |
I not sure how to frame the query for this. There is a way we can do it in PL/SQL using for loop statement but i need to achive this through SQL query