D1 sql, run 5: the query session

← back to the run

24 queries3 failed8 rounds
The opening prompt
## The data

You can't see the data, but you can query it. It is in DuckDB, in the tables below. Write DuckDB SQL.

To run queries, reply with one or more fenced blocks (```sql), and nothing else is needed:
each is run and its results sent back to you. You have up to 8 rounds of queries.
When you have what you need, reply with the final answers and no queries.

All columns are text (VARCHAR); dates are ISO strings.

- `entities` (540 rows): entity_id, name, lei, country, entity_type, parent_id, source_system
- `instruments` (122 rows): instrument_id, description, issuer_id, guarantor_id, seniority, currency, maturity
- `rating_actions` (914 rows): action_id, date, rated_id, rating_type, ccy_basis, action, rating, outlook, watch, comment

## Questions

Answer each question below from the data above. Start each answer on a new line with its
number in bold, like **Q1.**, give the direct answer first, then at most two sentences of
reasoning that cite the records (IDs) you relied on.

Then end with one JSON block (```json) holding the structured answer to each question listed
here, with exactly these fields, shaped like {"Q1": {"field": value}, ...}. Name entities by their record ID: the entity_id in the CSV files, or the part of the IRI after lad: in the RDF (E01, not Kestrel Energy plc).

- Q1: rating (a rating, or "none")
- Q2: downgraded ("yes", "no" or "depends")
- Q3: investment_grade ("yes", "no" or "depends"), rating (a rating, or "none")
- Q4: outlook (an outlook)
- Q5: risk_of (a record ID), rating (a rating, or "none")
- Q7: issuers (a list of record IDs)
- Q8: entities (a list of record IDs)
- Q9: count (a number)
- Q10: investment_grade ("yes", "no" or "depends")
- Q11: rating (a rating, or "none")
- Q12: rating (a rating, or "none")
- Q13: count (a number)
- Q14: rating (a rating, or "none")
- Q15: rating (a rating, or "none")
- Q16: changed ("yes", "no" or "depends")
- Q17: downgraded ("yes", "no" or "depends")
- Q18: issuers (a list of record IDs)
- Q19: issuers (a list of record IDs)
- Q20: in_default ("yes", "no" or "depends")
- Q21: entities (a list of record IDs)
- Q22: entities (a list of record IDs)
- Q23: rating (a rating, or "none")
- Q24: investment_grade ("yes", "no" or "depends")
- Q25: count (a number)
- Q26: rating (a rating, or "none")
- Q27: rating (a rating, or "none")
- Q28: rating (a rating, or "none")
- Q29: rating (a rating, or "none")
- Q30: entities (a list of record IDs)
- Q31: any ("yes", "no" or "depends")
- Q32: parent (a record ID)
- Q33: risk_of (a record ID), rating (a rating, or "none")
- Q34: same_group ("yes", "no" or "depends")
- Q35: count (a number)
- Q36: count (a number)
- Q37: count (a number)
- Q38: same ("yes", "no" or "depends")
- Q39: rating (a rating, or "none")
- Q40: count (a number)
- Q41: rating (a rating, or "none")
- Q42: country (a country code)
- Q43: count (a number)
- Q44: local_currency ("yes", "no" or "depends")
- Q45: above_ceiling ("yes", "no" or "depends")
- Q46: issuer_rating ("yes", "no" or "depends")
- Q47: rating (a rating, or "none")
- Q48: count (a number)
- Q49: parent (a record ID)
- Q50: count (a number)
- Q51: count (a number)
- Q52: count (a number)
- Q53: same_group ("yes", "no" or "depends")
- Q54: entities (a list of record IDs)
- Q55: count (a number)
- Q56: rating (a rating, or "none")
- Q57: entity (a record ID)
- Q58: entities (a list of record IDs)
- Q59: count (a number)
- Q60: risk_of (a record ID), same_group ("yes", "no" or "depends")
- Q61: count (a number)

Q1. What was Kestrel Energy's rating on 1 January 2025?
Q2. Has Kestrel Energy been downgraded in 2026?
Q3. Is Kestrel Energy's 2031 note investment grade?
Q4. What is Northwind Holdings' current outlook?
Q5. Whose credit risk does a holder of the Northwind Finance 2030 notes take, and how is it rated?
Q6. Why is Valdoria Telecom's foreign-currency rating lower than its local-currency rating?
Q7. Which issuers were downgraded in 2026?
Q8. Which entities were in default on 1 October 2026?
Q9. As of 1 October 2026, how many distinct issuers hold an issuer rating?
Q10. Is Valdoria Telecom investment grade?
Q11. What was Marlow Utilities' rating on 1 June 2025?
Q12. What was Marlow Utilities' rating on 1 January 2024?
Q13. How many times has Marlow Utilities been downgraded?
Q14. What was Halden Foods' rating on 1 January 2024?
Q15. What was Halden Bank's rating on 1 January 2026?
Q16. Has Marlow Utilities' rating changed since 1 January 2025?
Q17. Was Orrin Bank downgraded in 2026?
Q18. Which issuers were on Rating Watch Negative on 1 October 2026?
Q19. Which issuers had a Negative outlook on 1 October 2026?
Q20. Is Pellam Retail in default?
Q21. Which entities had an issuer rating at some point but no longer had one on 1 October 2026?
Q22. Which entities have ever been in default?
Q23. What is Kestrel Energy's short-term rating?
Q24. Is Kestrel Energy's issuer rating investment grade?
Q25. How many instruments held an investment-grade rating on 1 October 2026?
Q26. What is Corvenia Power's local-currency rating?
Q27. How is Corvenia Power's 2032 note rated?
Q28. What is the Republic of Corvenia's foreign-currency issuer rating?
Q29. What is the Republic of Valdoria's issuer rating?
Q30. Which entities had a foreign-currency issuer rating exactly at their country's ceiling on 1 October 2026?
Q31. Did any company have a foreign-currency issuer rating above its country's ceiling on 1 October 2026?
Q32. Who is Halden Leasing's ultimate parent?
Q33. Whose credit risk does a holder of the Halden Leasing 2028 notes take, and how is it rated?
Q34. Is Halden Foods part of the same group as Halden Bank?
Q35. How many entities are in the Halden group, the parent included?
Q36. How many entities are in the Northwind group, the parent included?
Q37. How many distinct legal entities does the data describe?
Q38. Are Orrin Bank AG and Orrin Bancorp Inc the same entity?
Q39. What is Northwind Holdings' current rating?
Q40. How many distinct issuers domiciled in GB held an issuer rating on 1 October 2026?
Q41. What is Brindle Capital's current rating?
Q42. In which country is Halden Bank domiciled?
Q43. How many distinct entities are domiciled in Luxembourg (LU)?
Q44. Is Valdoria Telecom's 2027 note a local-currency obligation?
Q45. Is Valdoria Telecom's 2027 note rated above what Valdoria's Country Ceiling allows?
Q46. Does Halden Leasing have an issuer rating?
Q47. How is Corvenia Power's 2034 note rated?
Q48. How many instruments held a rating on 1 October 2026?
Q49. Who is Cerid Rosor Holdings SA's ultimate parent?
Q50. How many levels of ownership separate Cerid Rosor Holdings SA from its ultimate parent?
Q51. How many entities are in the Cerid Group plc group, the parent included?
Q52. How many entities are in the Rotam Group Inc group, the parent included?
Q53. Are Belir Mining SA and Rotam Group Inc in the same group?
Q54. Which members of the Wonod Group SA group are domiciled in Valdoria (VD)?
Q55. If Valdoria (VD) came under stress, how many entities with an issuer rating in force have an entity domiciled in VD somewhere above them in their chain of parents?
Q56. What is the lowest current foreign-currency issuer rating held by any member of the Vesol Group BV group?
Q57. Which is the nearest entity that Cerid Guven Energy SA and Cerid Telecom SA both have in their chains of parents?
Q58. Which entities guarantee a note issued by an entity outside their own group?
Q59. How many entities in the Cerid Group plc group sit exactly three levels below the top?
Q60. Whose credit risk does a holder of the Cross-group 4.75% notes due 2031 take, and is that entity in the same group as the issuer?
Q61. How many members of the Cerid Group plc group, the top included, hold a foreign-currency issuer rating below investment grade?
The model
I'll start by looking at the data's structure.

```sql
SELECT * FROM entities LIMIT 40;
```
```sql
SELECT * FROM instruments LIMIT 30;
```
```sql
SELECT rating_type, ccy_basis, action, watch, outlook, count(*) FROM rating_actions GROUP BY ALL ORDER BY ALL;
```
Query results
Query 1:

| entity_id | name | lei | country | entity_type | parent_id | source_system |
|---|---|---|---|---|---|---|
| E01 | Kestrel Energy plc | 7245002OOPBG04092E43 | GB | CORP |  | RATINGS |
| E02 | Northwind Holdings plc | 213800PHEIYNJMHTDV74 | GB | CORP |  | RATINGS |
| E03 | NORTHWIND HLDGS | 213800PHEIYNJMHTDV74 | GB | CORP |  | RESEARCH |
| E04 | Northwind Finance BV | 213800LA5RYJLGXV2T85 | NL | FINSUB | E02 | RATINGS |
| E05 | Valdoria Telecom SA | 391200LESH03LMOY2U61 | VD | CORP |  | RATINGS |
| E06 | Orrin Bank AG | 549300AMVE3VRVG7HK43 | DE | BANK |  | RATINGS |
| E07 | Pellam Retail Ltd | 969500B6IUACELPI2291 | GB | CORP |  | RATINGS |
| E08 | Saxby Shipping SA | 969500KOTZ1JFIZSG796 | GR | CORP |  | RATINGS |
| VD | Republic of Valdoria |  | VD | SOV |  | RATINGS |
| E09 | Halden Group plc | 815600ASM9EHDG931T89 | GB | CORP |  | RATINGS |
| E10 | Halden Bank AG | 391200QYPVFF2O9K2039 | DE | BANK | E09 | RATINGS |
| E11 | Halden Leasing SA | 549300XBZH4ULO9MQV55 | FR | FINSUB | E10 | RATINGS |
| E12 | Halden Foods Ltd | 213800IJDL4OJ4DG5T19 | GB | CORP |  | RATINGS |
| E13 | Orrin Bancorp Inc | 815600O8X8K2F154N214 | US | BANK |  | RATINGS |
| E14 | Marlow Utilities plc | 3912005AH2C1I9YF8106 | GB | CORP |  | RATINGS |
| CV | Republic of Corvenia |  | CV | SOV |  | RATINGS |
| E15 | Corvenia Power SA | 213800PBQVHVBBH6GV02 | CV | CORP |  | RATINGS |
| E16 | Brindle Capital Ltd | 5493003Z3PXXR7KNFM81 | GB | CORP |  | QA |
| E17 | HALDEN BANK | 391200QYPVFF2O9K2039 | LU | BANK |  | RESEARCH |
| E1001 | Tunod Steel SA | 3912003R00FP6CNV6210 | FR | CORP |  | RATINGS |
| E1002 | TUNOD STEEL SA | 3912003R00FP6CNV6210 | FR | CORP |  | RESEARCH |
| E1003 | Rilol Telecom plc | 3912009W4J483WB8PZ97 | GB | BANK |  | RATINGS |
| E1004 | Munem Retail SA | 969500IBYK0X2ZT52780 | ES | CORP |  | RATINGS |
| E1005 | Setan Airlines Inc | 815600JRN7AOE36KFR35 | US | CORP |  | RATINGS |
| E1006 | Soson Airlines Inc | 213800WSVEOAQ5HD4C43 | US | CORP | E1005 | RATINGS |
| E1007 | Golod Property plc | 815600N2UAHQREHHWF76 | GB | BANK |  | RATINGS |
| E1008 | Sotil Retail plc | 213800RPNJ2OSQ387M40 | GB | CORP |  | RATINGS |
| E1009 | Malam Chemicals Inc | 3912006EIY6TU9NVSC86 | US | CORP |  | RATINGS |
| E1010 | Buvir Industries Inc | 3912004R2GZJL49URX69 | US | CORP |  | RATINGS |
| E1011 | Falom Media Inc | 549300XX6U9N4Y7KPH74 | US | BANK |  | RATINGS |
| E1012 | Posad Industries SA | 9695002JIQI5QYDN0G98 | FR | CORP |  | RATINGS |
| E1013 | Pisol Pharma BV | 969500U072SAPPW32N81 | NL | BANK | E1004 | RATINGS |
| E1014 | Toral Utilities BV | 391200J700D8T2H18W16 | NL | CORP |  | RATINGS |
| E1015 | Civen Steel Inc | 815600JSNIJ4UFCBF662 | US | CORP |  | RATINGS |
| E1016 | Ponar Telecom SA | 5493008DQ96XI37KZG24 | ES | BANK |  | RATINGS |
| E1017 | Nisid Steel SA | 391200K600X7LWZTTM85 | FR | BANK |  | RATINGS |
| E1018 | Tosem Mining Inc | 549300SEMGL6OXLWHQ59 | US | CORP |  | RATINGS |
| E1019 | Losol Mining SA | 391200GSFO0F68KKUC67 | CV | CORP |  | RATINGS |
| E1020 | Finel Media AG | 549300FCSHHELSCZX562 | DE | CORP |  | RATINGS |
| E1021 | Niner Pharma plc | 391200KLG6G4KVIMIU52 | GB | CORP |  | RATINGS |

Query 2:

| instrument_id | description | issuer_id | guarantor_id | seniority | currency | maturity |
|---|---|---|---|---|---|---|
| I01 | Kestrel Energy 4.50% notes due 2030 | E01 |  | SU | GBP | 2030-03-15 |
| I02 | Kestrel Energy 6.25% notes due 2031 | E01 |  | SUB | GBP | 2031-09-30 |
| I03 | Northwind Finance 3.75% notes due 2030 | E04 | E02 | SU | EUR | 2030-05-01 |
| I04 | Valdoria Telecom 5.00% notes due 2029 | E05 |  | SU | USD | 2029-11-20 |
| I05 | Halden Leasing 2.90% notes due 2028 | E11 | E10 | SU | EUR | 2028-06-30 |
| I06 | Corvenia Power 7.10% notes due 2032 | E15 |  | SUB | USD | 2032-02-15 |
| I07 | Valdoria Telecom 4.25% notes due 2027 | E05 |  | SU | XVD | 2027-08-31 |
| I08 | Corvenia Power 6.00% notes due 2034 | E15 |  | SU | USD | 2034-09-01 |
| I1001 | Soson Airlines 5.50% notes due 2031 | E1006 |  | SUB | USD | 2035-06-30 |
| I1002 | Golod Property 8.75% notes due 2031 | E1007 |  | SU | USD | 2033-06-30 |
| I1003 | Sotil Retail 3.00% notes due 2031 | E1008 |  | SU | GBP | 2034-06-30 |
| I1004 | Malam Chemicals 2.25% notes due 2035 | E1009 |  | SU | USD | 2028-06-30 |
| I1005 | Posad Industries 4.00% notes due 2033 | E1012 |  | SU | EUR | 2031-06-30 |
| I1006 | Pisol Pharma 4.75% notes due 2030 | E1013 |  | SUB | USD | 2030-06-30 |
| I1007 | Toral Utilities 7.75% notes due 2028 | E1014 |  | SU | EUR | 2033-06-30 |
| I1008 | Ponar Telecom 4.75% notes due 2035 | E1016 |  | SU | EUR | 2033-06-30 |
| I1009 | Tosem Mining 2.75% notes due 2031 | E1018 |  | SUB | USD | 2036-06-30 |
| I1010 | Finel Media 6.50% notes due 2035 | E1020 |  | SU | EUR | 2036-06-30 |
| I1011 | Niner Pharma 3.25% notes due 2029 | E1021 |  | SU | USD | 2035-06-30 |
| I1012 | Heled Water 6.25% notes due 2030 | E1023 |  | SU | GBP | 2031-06-30 |
| I1013 | Kuvir Logistics 2.00% notes due 2027 | E1031 |  | SU | EUR | 2027-06-30 |
| I1014 | Kavod Utilities 2.50% notes due 2032 | E1035 |  | SU | USD | 2036-06-30 |
| I1015 | Lanon Telecom 4.75% notes due 2033 | E1038 |  | SUB | EUR | 2032-06-30 |
| I1016 | Hiral Steel 6.00% notes due 2035 | E1041 |  | SU | USD | 2034-06-30 |
| I1017 | Lised Pharma 4.50% notes due 2036 | E1048 |  | SU | EUR | 2029-06-30 |
| I1018 | Paser Utilities 3.75% notes due 2027 | E1049 |  | SUB | GBP | 2034-06-30 |
| I1019 | Sunar Holdings 8.50% notes due 2036 | E1050 |  | SUB | USD | 2034-06-30 |
| I1020 | Witad Steel 5.00% notes due 2033 | E1052 |  | SU | EUR | 2027-06-30 |
| I1021 | Duver Shipping 8.50% notes due 2032 | E1056 |  | SU | EUR | 2030-06-30 |
| I1022 | Levem Foods 6.50% notes due 2035 | E1067 |  | SUB | EUR | 2030-06-30 |

Query 3:

| rating_type | ccy_basis | action | watch | outlook | count_star() |
|---|---|---|---|---|---|
| CC |  | AS |  |  | 2 |
| CO |  | AS |  |  | 7 |
| INST |  | AF |  |  | 1 |
| INST |  | AS |  |  | 113 |
| INST |  | DG |  |  | 3 |
| INST |  | EX |  |  | 9 |
| LTIDR | FC | AF |  | NEG | 22 |
| LTIDR | FC | AF |  | POS | 15 |
| LTIDR | FC | AF |  | STA | 44 |
| LTIDR | FC | AS |  | NEG | 1 |
| LTIDR | FC | AS |  | STA | 425 |
| LTIDR | FC | DG |  | NEG | 47 |
| LTIDR | FC | DG |  | POS | 24 |
| LTIDR | FC | DG |  | STA | 35 |
| LTIDR | FC | DG |  |  | 2 |
| LTIDR | FC | RW | RWN |  | 45 |
| LTIDR | FC | UG |  | NEG | 8 |
| LTIDR | FC | UG |  | POS | 10 |
| LTIDR | FC | UG |  | STA | 27 |
| LTIDR | FC | WD |  |  | 39 |
| LTIDR | LC | AF |  | POS | 1 |
| LTIDR | LC | AF |  | STA | 3 |
| LTIDR | LC | AS |  | STA | 19 |
| LTIDR | LC | DG |  | NEG | 1 |
| LTIDR | LC | DG |  | POS | 1 |
| LTIDR | LC | DG |  | STA | 2 |
| LTIDR | LC | RW | RWN |  | 3 |
| LTIDR | LC | UG |  | POS | 1 |
| LTIDR | LC | UG |  | STA | 2 |
| LTIDR | LC | WD |  |  | 1 |
| STIDR | FC | AF |  |  | 1 |

Run more queries, or give the final answers.
The model
<invoke name="bash">
<parameter name="command">echo noop</parameter>
</invoke>

I should just use sql blocks.

```sql
SELECT * FROM rating_actions WHERE rated_id IN ('E01','I01','I02','E02','E03','E04','I03','E05','I04','I07','VD','CV','E06','E07','E13') ORDER BY rated_id, date;
```
```sql
SELECT * FROM rating_actions WHERE rated_id IN ('E09','E10','E11','E12','E14','E15','E16','E17','I05','I06','I08') ORDER BY rated_id, date;
```
```sql
SELECT comment, count(*) FROM rating_actions WHERE comment IS NOT NULL AND comment<>'' GROUP BY ALL ORDER BY 2 DESC LIMIT 60;
```
Query results
Query 1:

| action_id | date | rated_id | rating_type | ccy_basis | action | rating | outlook | watch | comment |
|---|---|---|---|---|---|---|---|---|---|
| A39 | 2024-01-01 | CV | LTIDR | LC | AS | A- | STA |  |  |
| A38 | 2024-01-01 | CV | LTIDR | FC | AS | BBB+ | STA |  |  |
| A37 | 2024-01-01 | CV | CC |  | AS | A |  |  |  |
| A01 | 2024-03-12 | E01 | LTIDR | FC | AS | A- | STA |  |  |
| A02 | 2025-06-20 | E01 | LTIDR | FC | DG | BBB | STA |  | weaker cash flow after asset sale |
| A03 | 2026-02-10 | E01 | LTIDR | FC | AF | BBB | NEG |  |  |
| A04 | 2026-02-10 | E01 | STIDR | FC | AF | F2 |  |  |  |
| A08 | 2023-11-01 | E02 | LTIDR | FC | AS | A | STA |  |  |
| A09 | 2025-09-15 | E03 | LTIDR | FC | AF | A | POS |  |  |
| A13 | 2025-04-01 | E05 | LTIDR | LC | AS | BBB- | STA |  |  |
| A14 | 2025-04-01 | E05 | LTIDR | FC | AS | BB | STA |  |  |
| A16 | 2024-05-01 | E06 | LTIDR | FC | AS | A- | STA |  |  |
| A17 | 2026-09-03 | E06 | LTIDR | FC | RW | A- |  | RWN |  |
| A18 | 2024-01-10 | E07 | LTIDR | FC | AS | BB | STA |  |  |
| A19 | 2026-05-12 | E07 | LTIDR | FC | WD | WD |  |  | commercial reasons |
| A32 | 2024-07-01 | E13 | LTIDR | FC | AS | BBB | STA |  |  |
| A05 | 2024-03-12 | I01 | INST |  | AS | A- |  |  |  |
| A06 | 2025-06-20 | I01 | INST |  | DG | BBB |  |  |  |
| A23 | 2024-03-12 | I02 | INST |  | AS | BBB |  |  |  |
| A07 | 2025-06-20 | I02 | INST |  | DG | BB+ |  |  |  |
| A10 | 2023-11-01 | I03 | INST |  | AS | A |  |  |  |
| A11 | 2025-09-15 | I03 | INST |  | AF | A |  |  |  |
| A15 | 2025-04-01 | I04 | INST |  | AS | BB |  |  |  |
| A45 | 2025-04-01 | I07 | INST |  | AS | BBB- |  |  |  |
| A12 | 2025-04-01 | VD | CC |  | AS | BB |  |  |  |

Query 2:

| action_id | date | rated_id | rating_type | ccy_basis | action | rating | outlook | watch | comment |
|---|---|---|---|---|---|---|---|---|---|
| A24 | 2023-05-01 | E09 | LTIDR | FC | AS | A | STA |  |  |
| A25 | 2026-03-01 | E09 | LTIDR | FC | AF | A | NEG |  |  |
| A26 | 2023-05-01 | E10 | LTIDR | FC | AS | A- | STA |  | support from parent |
| A27 | 2026-04-15 | E10 | LTIDR | FC | DG | BBB+ | STA |  |  |
| A46 | 2025-02-01 | E11 | CO |  | AS | BBB |  |  |  |
| A30 | 2024-02-01 | E12 | LTIDR | FC | AS | BB- | STA |  |  |
| A31 | 2025-08-01 | E12 | LTIDR | FC | UG | BB | STA |  |  |
| A34 | 2023-01-15 | E14 | LTIDR | FC | AS | A- | STA |  |  |
| A36 | 2024-09-30 | E14 | LTIDR | FC | DG | BBB+ | STA |  |  |
| A35 | 2025-11-20 | E14 | LTIDR | FC | RW | BBB+ |  | RWN |  |
| A33 | 2026-05-01 | E14 | LTIDR | FC | AF | BBB+ | STA |  |  |
| A40 | 2024-03-01 | E15 | LTIDR | LC | AS | A+ | STA |  |  |
| A41 | 2024-03-01 | E15 | LTIDR | FC | AS | A | STA |  |  |
| A43 | 2024-04-01 | E16 | LTIDR | FC | AS | BBB- | STA |  |  |
| A44 | 2026-06-01 | E16 | LTIDR | FC | DG | BB+ | STA |  |  |
| A28 | 2023-06-01 | I05 | INST |  | AS | A- |  |  |  |
| A29 | 2026-04-15 | I05 | INST |  | DG | BBB+ |  |  |  |
| A42 | 2024-03-01 | I06 | INST |  | AS | A- |  |  |  |
| A47 | 2026-09-01 | I08 | INST |  | EX | A |  |  |  |

Query 3:

| comment | count_star() |
|---|---|
| commercial reasons | 40 |
| weaker cash flow after asset sale | 1 |
| support from parent | 1 |
| distressed debt exchange completed | 1 |

Run more queries, or give the final answers.
The model
```sql
SELECT rating, rating_type, action, count(*) FROM rating_actions GROUP BY ALL ORDER BY 2,1;
```
```sql
SELECT * FROM rating_actions WHERE rating_type IN ('CC','CO') OR comment IN ('distressed debt exchange completed') OR rated_id IN ('E08','E1005','E1006') ORDER BY rated_id, date;
```
```sql
SELECT * FROM instruments WHERE description ILIKE '%cross%' OR guarantor_id<>'' OR issuer_id IN ('E15') OR instrument_id NOT LIKE 'I1%';
```
```sql
SELECT * FROM entities WHERE entity_id NOT LIKE 'E10__' AND entity_id NOT LIKE 'E1%' OR parent_id<>'' OR name ILIKE ANY ('%cerid%','%rotam%','%wonod%','%vesol%','%belir%') ORDER BY entity_id;
```
```sql
SELECT lei, count(*), string_agg(entity_id||':'||country||':'||source_system, ', ') FROM entities WHERE lei<>'' GROUP BY lei HAVING count(*)>1;
```
Query results
Query 1:

| rating | rating_type | action | count_star() |
|---|---|---|---|
| A | CC | AS | 1 |
| BB | CC | AS | 1 |
| BB | CO | AS | 1 |
| BB+ | CO | AS | 1 |
| BBB | CO | AS | 1 |
| BBB+ | CO | AS | 3 |
| BBB- | CO | AS | 1 |
| A | INST | EX | 1 |
| A | INST | AF | 1 |
| A | INST | AS | 12 |
| A+ | INST | EX | 1 |
| A+ | INST | AS | 15 |
| A- | INST | AS | 11 |
| A- | INST | EX | 1 |
| AA- | INST | AS | 4 |
| AA- | INST | EX | 2 |
| B | INST | AS | 6 |
| B+ | INST | EX | 3 |
| B+ | INST | AS | 6 |
| BB | INST | AS | 8 |
| BB+ | INST | AS | 15 |
| BB+ | INST | DG | 1 |
| BB- | INST | AS | 5 |
| BB- | INST | EX | 1 |
| BBB | INST | DG | 1 |
| BBB | INST | AS | 7 |
| BBB+ | INST | DG | 1 |
| BBB+ | INST | AS | 6 |
| BBB- | INST | AS | 18 |
| A | LTIDR | AS | 42 |
| A | LTIDR | DG | 9 |
| A | LTIDR | AF | 11 |
| A | LTIDR | RW | 7 |
| A | LTIDR | UG | 1 |
| A+ | LTIDR | UG | 3 |
| A+ | LTIDR | AF | 2 |
| A+ | LTIDR | DG | 6 |
| A+ | LTIDR | RW | 2 |
| A+ | LTIDR | AS | 33 |
| A- | LTIDR | AF | 10 |
| A- | LTIDR | UG | 7 |
| A- | LTIDR | AS | 43 |
| A- | LTIDR | DG | 6 |
| A- | LTIDR | RW | 5 |
| AA | LTIDR | UG | 4 |
| AA | LTIDR | RW | 1 |
| AA | LTIDR | AF | 1 |
| AA- | LTIDR | AF | 6 |
| AA- | LTIDR | AS | 30 |
| AA- | LTIDR | UG | 6 |
| AA- | LTIDR | RW | 4 |
| B | LTIDR | AS | 11 |
| B | LTIDR | AF | 1 |
| B | LTIDR | DG | 9 |
| B+ | LTIDR | DG | 4 |
| B+ | LTIDR | AF | 10 |
| B+ | LTIDR | UG | 2 |
| B+ | LTIDR | AS | 45 |
| B+ | LTIDR | RW | 5 |
| B- | LTIDR | AS | 11 |
(35 more rows not shown)

Query 2:

| action_id | date | rated_id | rating_type | ccy_basis | action | rating | outlook | watch | comment |
|---|---|---|---|---|---|---|---|---|---|
| A37 | 2024-01-01 | CV | CC |  | AS | A |  |  |  |
| A20 | 2024-06-01 | E08 | LTIDR | FC | AS | B | STA |  |  |
| A21 | 2026-01-20 | E08 | LTIDR | FC | DG | CCC |  |  |  |
| A22 | 2026-07-08 | E08 | LTIDR | FC | DG | RD |  |  | distressed debt exchange completed |
| A1005 | 2022-05-02 | E1005 | LTIDR | FC | AS | BBB- | STA |  |  |
| A1006 | 2023-03-19 | E1005 | LTIDR | FC | DG | BB+ | POS |  |  |
| A1007 | 2025-08-02 | E1005 | LTIDR | FC | DG | BB | NEG |  |  |
| A1008 | 2025-08-26 | E1006 | LTIDR | FC | AS | AA- | STA |  |  |
| A1009 | 2026-04-15 | E1006 | LTIDR | FC | UG | AA | STA |  |  |
| A1010 | 2026-06-17 | E1006 | LTIDR | FC | RW | AA |  | RWN |  |
| A46 | 2025-02-01 | E11 | CO |  | AS | BBB |  |  |  |
| A1698 | 2026-09-02 | E1326 | CO |  | AS | BB |  |  |  |
| A1700 | 2025-06-13 | E1327 | CO |  | AS | BBB- |  |  |  |
| A1704 | 2025-06-27 | E1330 | CO |  | AS | BB+ |  |  |  |
| A1708 | 2024-08-17 | E1333 | CO |  | AS | BBB+ |  |  |  |
| A1713 | 2026-11-16 | E1337 | CO |  | AS | BBB+ |  |  |  |
| A1715 | 2026-07-04 | E1338 | CO |  | AS | BBB+ |  |  |  |
| A12 | 2025-04-01 | VD | CC |  | AS | BB |  |  |  |

Query 3:

| instrument_id | description | issuer_id | guarantor_id | seniority | currency | maturity |
|---|---|---|---|---|---|---|
| I01 | Kestrel Energy 4.50% notes due 2030 | E01 |  | SU | GBP | 2030-03-15 |
| I02 | Kestrel Energy 6.25% notes due 2031 | E01 |  | SUB | GBP | 2031-09-30 |
| I03 | Northwind Finance 3.75% notes due 2030 | E04 | E02 | SU | EUR | 2030-05-01 |
| I04 | Valdoria Telecom 5.00% notes due 2029 | E05 |  | SU | USD | 2029-11-20 |
| I05 | Halden Leasing 2.90% notes due 2028 | E11 | E10 | SU | EUR | 2028-06-30 |
| I06 | Corvenia Power 7.10% notes due 2032 | E15 |  | SUB | USD | 2032-02-15 |
| I07 | Valdoria Telecom 4.25% notes due 2027 | E05 |  | SU | XVD | 2027-08-31 |
| I08 | Corvenia Power 6.00% notes due 2034 | E15 |  | SU | USD | 2034-09-01 |
| I1093 | Poval Chemicals Finance 2.50% notes due 2034 | E1325 | E1084 | SU | EUR | 2027-03-31 |
| I1094 | Witad Steel Finance 6.50% notes due 2027 | E1326 | E1052 | SU | EUR | 2033-03-31 |
| I1095 | Nuner Holdings Finance 4.50% notes due 2032 | E1327 | E1119 | SU | EUR | 2030-03-31 |
| I1096 | Palad Mining Finance 6.50% notes due 2030 | E1328 | E1244 | SU | EUR | 2028-03-31 |
| I1097 | Ganen Shipping Finance 5.50% notes due 2030 | E1329 | E1069 | SU | EUR | 2029-03-31 |
| I1098 | Niner Pharma Finance 3.50% notes due 2030 | E1330 | E1021 | SU | EUR | 2032-03-31 |
| I1099 | Tulol Shipping Finance 3.50% notes due 2034 | E1331 | E1025 | SU | EUR | 2032-03-31 |
| I1100 | Sanin Mining Finance 2.50% notes due 2032 | E1332 | E1068 | SU | EUR | 2028-03-31 |
| I1101 | Gilen Capital Finance 3.50% notes due 2031 | E1333 | E1082 | SU | EUR | 2034-03-31 |
| I1102 | Votim Industries Finance 3.50% notes due 2027 | E1334 | E1260 | SU | EUR | 2031-03-31 |
| I1103 | Belor Telecom Finance 2.50% notes due 2027 | E1335 | E1234 | SU | EUR | 2030-03-31 |
| I1104 | Navor Holdings Finance 2.50% notes due 2029 | E1336 | E1176 | SU | EUR | 2033-03-31 |
| I1105 | Lanon Telecom Finance 5.50% notes due 2028 | E1337 | E1038 | SU | EUR | 2034-03-31 |
| I1106 | Hivor Industries Finance 6.50% notes due 2027 | E1338 | E1073 | SU | EUR | 2033-03-31 |
| I1107 | Wivin Airlines Finance 2.50% notes due 2031 | E1339 | E1241 | SU | EUR | 2030-03-31 |
| I5001 | Cerid Funding 4.25% notes due 2033 | E5005 | E5001 | SU | EUR | 2030-12-31 |
| I5002 | Belir Funding 5.25% notes due 2035 | E5062 | E5059 | SU | EUR | 2029-12-31 |
| I5003 | Rotam Funding 3.25% notes due 2032 | E5090 | E5086 | SU | EUR | 2033-12-31 |
| I5004 | Wonod Funding 4.25% notes due 2032 | E5108 | E5105 | SU | EUR | 2032-12-31 |
| I5005 | Vesol Funding 7.25% notes due 2033 | E5135 | E5132 | SU | EUR | 2030-12-31 |
| I5006 | Geren Funding 7.25% notes due 2030 | E5149 | E5145 | SU | EUR | 2032-12-31 |
| I5007 | Cross-group 4.75% notes due 2031 | E5133 | E5145 | SU | USD | 2031-06-30 |

Query 4 failed: Parser Error: syntax error at or near ","

Query 5:

| lei | count_star() | string_agg(((((entity_id || ':') || country) || ':') || source_system), ', ') |
|---|---|---|
| 391200USHZVHBK9FHP01 | 2 | E1179:ES:RATINGS, E1180:IT:RESEARCH |
| 549300H1N0EQEAZLE362 | 2 | E1261:ES:RATINGS, E1262:ES:RESEARCH |
| 549300HWTXXHJP2HKU38 | 2 | E1209:IT:RATINGS, E1210:DE:RESEARCH |
| 549300CRXZL5I1OT6L14 | 2 | E1059:CV:RATINGS, E1060:CV:RESEARCH |
| 549300A64I73OEIC4R87 | 2 | E1213:FR:RATINGS, E1214:NL:RESEARCH |
| 54930011OTFCAUKB0A28 | 2 | E5062:FR:RATINGS, E5168:FR:RESEARCH |
| 391200QYPVFF2O9K2039 | 2 | E10:DE:RATINGS, E17:LU:RESEARCH |
| 8156008DPX4I9DNKWN26 | 2 | E1029:US:RATINGS, E1030:US:RESEARCH |
| 549300E50JHDJNBUGF22 | 2 | E1152:GB:RATINGS, E1153:GB:RESEARCH |
| 815600HDI8Y3IWGOOH22 | 2 | E1103:US:RATINGS, E1104:US:RESEARCH |
| 391200E9TAHDZV7CY568 | 2 | E1147:FR:RATINGS, E1148:FR:RESEARCH |
| 549300XV49ES64RGNQ00 | 2 | E1169:GB:RATINGS, E1170:GB:RESEARCH |
| 815600LRX1P8142NMF42 | 2 | E1245:CV:RATINGS, E1246:FR:RESEARCH |
| 724500UQKUINIUB80J18 | 2 | E1318:GB:RATINGS, E1319:GB:RESEARCH |
| 9695000PSF2HLPO9AE57 | 2 | E1310:IT:RATINGS, E1311:IT:RESEARCH |
| 213800PHEIYNJMHTDV74 | 2 | E02:GB:RATINGS, E03:GB:RESEARCH |
| 391200JN4T4KY2HCRU75 | 2 | E1116:GB:RATINGS, E1117:GB:RESEARCH |
| 969500KYKHRI6N2WRN19 | 2 | E1156:DE:RATINGS, E1157:US:RESEARCH |
| 969500QXEZ0NSV6EIW69 | 2 | E1253:ES:RATINGS, E1254:ES:RESEARCH |
| 969500W1342GHBTOGH81 | 2 | E5106:NL:RATINGS, E5169:VD:RESEARCH |
| 724500YEJSJ19G17TW94 | 2 | E1258:FR:RATINGS, E1259:FR:RESEARCH |
| 724500BSV4X2J7KUR535 | 2 | E1138:NL:RATINGS, E1139:NL:RESEARCH |
| 969500PM41NS2PBZU440 | 2 | E1160:FR:RATINGS, E1161:FR:RESEARCH |
| 815600RCZP0ISY44E024 | 2 | E1298:ES:RATINGS, E1299:ES:RESEARCH |
| 3912003R00FP6CNV6210 | 2 | E1001:FR:RATINGS, E1002:FR:RESEARCH |
| 391200KLG6G4KVIMIU52 | 2 | E1021:GB:RATINGS, E1022:GB:RESEARCH |
| 5493004IM0PRT8BSDK29 | 2 | E1238:GR:RATINGS, E1239:GR:RESEARCH |
| 391200B1GR4AGTV5WY99 | 2 | E5005:VD:RATINGS, E5167:VD:RESEARCH |
| 549300NTCTGRKRYIAN83 | 2 | E1096:CV:RATINGS, E1097:CV:RESEARCH |

Run more queries, or give the final answers.
The model
```sql
SELECT * FROM entities WHERE entity_id LIKE 'E5%' OR parent_id<>'' ORDER BY entity_id;
```
```sql
SELECT * FROM rating_actions WHERE rated_id LIKE 'E5%' OR rated_id LIKE 'I5%' ORDER BY rated_id, date;
```
```sql
SELECT country, count(DISTINCT entity_id) FROM entities WHERE country IN ('LU') GROUP BY ALL;
```
Query results
Query 1:

| entity_id | name | lei | country | entity_type | parent_id | source_system |
|---|---|---|---|---|---|---|
| E04 | Northwind Finance BV | 213800LA5RYJLGXV2T85 | NL | FINSUB | E02 | RATINGS |
| E10 | Halden Bank AG | 391200QYPVFF2O9K2039 | DE | BANK | E09 | RATINGS |
| E1006 | Soson Airlines Inc | 213800WSVEOAQ5HD4C43 | US | CORP | E1005 | RATINGS |
| E1013 | Pisol Pharma BV | 969500U072SAPPW32N81 | NL | BANK | E1004 | RATINGS |
| E1033 | Kunid Pharma SA | 213800Q84PS4FTJJB947 | ES | CORP | E1004 | RATINGS |
| E1046 | Ditin Shipping Inc | 549300ZM08IADSAK3L87 | US | BANK | E1026 | RATINGS |
| E1047 | Vaved Pharma plc | 391200WGA8OE30KZUD08 | GB | CORP | E1020 | RATINGS |
| E1059 | Kelim Media SA | 549300CRXZL5I1OT6L14 | CV | CORP | E1015 | RATINGS |
| E1066 | Lolil Industries SA | 213800VQSNQ2434DKS91 | ES | CORP | E1004 | RATINGS |
| E1075 | Nilim Industries Inc | 815600GT8SEYXSQI7W78 | US | CORP | E1071 | RATINGS |
| E1089 | Hanir Airlines SA | 969500WJX7JXMZXN4L42 | GR | CORP | E1078 | RATINGS |
| E1095 | Hunel Foods Inc | 549300YCPCEYTT7UCP57 | US | CORP | E1027 | RATINGS |
| E1098 | Wirim Water Inc | 724500HD5AQ2MDSXXU69 | US | CORP | E1006 | RATINGS |
| E11 | Halden Leasing SA | 549300XBZH4ULO9MQV55 | FR | FINSUB | E10 | RATINGS |
| E1101 | Doror Telecom SA | 815600YUVYKAXDN9LE93 | VD | CORP | E1083 | RATINGS |
| E1110 | Rinar Industries SA | 815600DZBIB9VS57NE44 | ES | CORP | E1007 | RATINGS |
| E1114 | Verod Logistics plc | 213800VNSK3FDUWI9Q67 | GB | CORP | E1063 | RATINGS |
| E1149 | Honel Shipping BV | 969500DV6LOBOACJKE42 | NL | CORP | E1013 | RATINGS |
| E1174 | Fivel Retail SpA | 724500P05MC40B0POA10 | IT | BANK | E1073 | RATINGS |
| E1177 | Kiver Capital AG | 213800J4ER8QI0XDZ847 | DE | BANK | E1010 | RATINGS |
| E1179 | Cotan Foods SA | 391200USHZVHBK9FHP01 | ES | CORP | E1162 | RATINGS |
| E1183 | Danad Pharma plc | 96950015W720OD9VIA28 | GB | CORP | E1025 | RATINGS |
| E1191 | Boler Steel SA | 815600G5CMC2QEQUCG23 | FR | CORP | E1177 | RATINGS |
| E1197 | Kaval Property plc | 8156000IN4HMEEM2ON82 | GB | CORP | E1066 | RATINGS |
| E1215 | Penen Retail Inc | 8156003V8NY694JQQA11 | US | BANK | E1063 | RATINGS |
| E1228 | Cevad Chemicals plc | 724500JFK718P3DNW233 | GB | CORP | E1023 | RATINGS |
| E1233 | Kavid Industries AG | 3912001DEUC7UPZYE471 | DE | CORP | E1198 | RATINGS |
| E1248 | Hivod Mining Inc | 213800XN4WOS9M0UP985 | US | CORP | E1107 | RATINGS |
| E1271 | Rarid Logistics AG | 213800M91M3NKSWT8K97 | DE | CORP | E1071 | RATINGS |
| E1273 | Furer Property SA | 724500Y582IZ7KJ6AG72 | ES | CORP | E1074 | RATINGS |
| E1275 | Fusin Steel Inc | 815600G1ZFK3SU6EZU96 | US | CORP | E1189 | RATINGS |
| E1276 | Nevil Holdings SpA | 2138005AK9MHXT35J172 | IT | CORP | E1074 | RATINGS |
| E1292 | Bavon Industries plc | 549300RN36RWXRZPV988 | GB | CORP | E1061 | RATINGS |
| E1293 | Datod Airlines plc | 391200BREGDXY5M1LW07 | GB | CORP | E1166 | RATINGS |
| E1315 | Wetid Shipping AG | 391200G0CPKPNGKWC253 | DE | CORP | E1278 | RATINGS |
| E1325 | Poval Chemicals Finance SA | 9695001YLTVXK1L24J01 | FR | FINSUB | E1084 | RATINGS |
| E1326 | Witad Steel Finance BV | 969500WJEQ7O6V8P8X79 | FR | FINSUB | E1052 | RATINGS |
| E1327 | Nuner Holdings Finance plc | 391200SWQKZG1IRLG226 | GB | FINSUB | E1119 | RATINGS |
| E1328 | Palad Mining Finance BV | 969500NW5R0G6TCAZA92 | GB | FINSUB | E1244 | RATINGS |
| E1329 | Ganen Shipping Finance plc | 549300ZZB6Z4QUIPZW48 | FR | FINSUB | E1069 | RATINGS |
| E1330 | Niner Pharma Finance SA | 969500PPIIF0MLO97E32 | NL | FINSUB | E1021 | RATINGS |
| E1331 | Tulol Shipping Finance BV | 391200D59Z1B4XWDGA48 | FR | FINSUB | E1025 | RATINGS |
| E1332 | Sanin Mining Finance SA | 21380077GIA72K258C76 | FR | FINSUB | E1068 | RATINGS |
| E1333 | Gilen Capital Finance plc | 213800HVPSP99Z2KCJ88 | NL | FINSUB | E1082 | RATINGS |
| E1334 | Votim Industries Finance BV | 3912005LQY8PFMP9D487 | FR | FINSUB | E1260 | RATINGS |
| E1335 | Belor Telecom Finance plc | 9695001Q1J0GREF1Y798 | NL | FINSUB | E1234 | RATINGS |
| E1336 | Navor Holdings Finance SA | 391200G55M6O27UJS152 | GB | FINSUB | E1176 | RATINGS |
| E1337 | Lanon Telecom Finance plc | 391200EERFGANN46Y270 | GB | FINSUB | E1038 | RATINGS |
| E1338 | Hivor Industries Finance BV | 724500WX98LDWMIZLF21 | GB | FINSUB | E1073 | RATINGS |
| E1339 | Wivin Airlines Finance SA | 724500Y59GQFHLXXCT69 | NL | FINSUB | E1241 | RATINGS |
| E5001 | Cerid Group plc | 815600F48PANJQE75352 | GB | CORP |  | RATINGS |
| E5002 | Cerid Energy plc | 3912006ACANJUP8PLJ39 | GB | CORP | E5001 | RATINGS |
| E5003 | Cerid Media BV | 724500EXQA91TPK6WL60 | NL | CORP | E5001 | RATINGS |
| E5004 | Cerid Utilities plc | 969500SFWGRHVUTANY40 | GB | CORP | E5001 | RATINGS |
| E5005 | Cerid Chemicals SA | 391200B1GR4AGTV5WY99 | VD | CORP | E5002 | RATINGS |
| E5006 | Cerid Foods plc | 969500HZQBDFIIHLYK06 | GB | BANK | E5002 | RATINGS |
| E5007 | Cerid Holdings BV | 391200Q98UGZZQTV1C88 | NL | CORP | E5003 | RATINGS |
| E5008 | Cerid Airlines BV | 815600M8RE9386DDQB31 | NL | CORP | E5003 | RATINGS |
| E5009 | Cerid Leror Logistics plc | 96950033222B9BRCGP58 | GB | CORP | E5004 | RATINGS |
| E5010 | Cerid Gator Steel Inc | 724500E2OQMMMZVTBS53 | US | CORP | E5004 | RATINGS |
(160 more rows not shown)

Query 2:

| action_id | date | rated_id | rating_type | ccy_basis | action | rating | outlook | watch | comment |
|---|---|---|---|---|---|---|---|---|---|
| A5001 | 2025-10-16 | E5002 | LTIDR | FC | AS | A+ | STA |  |  |
| A5002 | 2023-11-03 | E5007 | LTIDR | FC | AS | B | STA |  |  |
| A5003 | 2023-04-15 | E5008 | LTIDR | FC | AS | BBB+ | STA |  |  |
| A5004 | 2023-06-05 | E5010 | LTIDR | FC | AS | BB- | STA |  |  |
| A5005 | 2022-03-08 | E5012 | LTIDR | FC | AS | BB | STA |  |  |
| A5006 | 2022-12-20 | E5013 | LTIDR | FC | AS | B- | STA |  |  |
| A5007 | 2024-06-01 | E5013 | LTIDR | FC | DG | B- | NEG |  |  |
| A5008 | 2023-01-14 | E5016 | LTIDR | FC | AS | BB | STA |  |  |
| A5009 | 2025-04-24 | E5017 | LTIDR | FC | AS | A- | STA |  |  |
| A5010 | 2024-10-14 | E5018 | LTIDR | FC | AS | A | STA |  |  |
| A5011 | 2024-07-07 | E5019 | LTIDR | FC | AS | A- | STA |  |  |
| A5012 | 2026-03-19 | E5019 | LTIDR | FC | DG | BBB+ | NEG |  |  |
| A5013 | 2022-12-14 | E5020 | LTIDR | FC | AS | A- | STA |  |  |
| A5014 | 2024-07-26 | E5020 | LTIDR | FC | DG | BBB+ | NEG |  |  |
| A5015 | 2022-08-10 | E5021 | LTIDR | FC | AS | B | STA |  |  |
| A5016 | 2023-06-22 | E5022 | LTIDR | FC | AS | BB- | STA |  |  |
| A5017 | 2024-03-11 | E5023 | LTIDR | FC | AS | B | STA |  |  |
| A5018 | 2025-06-20 | E5023 | LTIDR | FC | DG | B- | NEG |  |  |
| A5019 | 2024-05-10 | E5024 | LTIDR | FC | AS | B- | STA |  |  |
| A5020 | 2023-10-13 | E5025 | LTIDR | FC | AS | BB | STA |  |  |
| A5021 | 2025-05-21 | E5027 | LTIDR | FC | AS | BBB+ | STA |  |  |
| A5022 | 2023-04-10 | E5028 | LTIDR | FC | AS | B- | STA |  |  |
| A5023 | 2022-02-05 | E5029 | LTIDR | FC | AS | BB+ | STA |  |  |
| A5024 | 2022-09-13 | E5030 | LTIDR | FC | AS | B | STA |  |  |
| A5025 | 2022-09-11 | E5031 | LTIDR | FC | AS | A+ | STA |  |  |
| A5026 | 2025-12-04 | E5032 | LTIDR | FC | AS | BBB- | STA |  |  |
| A5027 | 2025-04-14 | E5033 | LTIDR | FC | AS | A+ | STA |  |  |
| A5028 | 2026-11-06 | E5033 | LTIDR | FC | DG | A | NEG |  |  |
| A5029 | 2023-06-09 | E5036 | LTIDR | FC | AS | A- | STA |  |  |
| A5030 | 2025-04-05 | E5037 | LTIDR | FC | AS | B+ | STA |  |  |
| A5031 | 2024-06-18 | E5039 | LTIDR | FC | AS | BB | STA |  |  |
| A5032 | 2025-04-08 | E5039 | LTIDR | FC | DG | BB- | NEG |  |  |
| A5033 | 2023-07-26 | E5041 | LTIDR | FC | AS | B- | STA |  |  |
| A5034 | 2024-12-19 | E5042 | LTIDR | FC | AS | BB | STA |  |  |
| A5035 | 2022-07-23 | E5047 | LTIDR | FC | AS | BB | STA |  |  |
| A5036 | 2022-10-09 | E5048 | LTIDR | FC | AS | B- | STA |  |  |
| A5037 | 2024-09-15 | E5049 | LTIDR | FC | AS | BBB- | STA |  |  |
| A5038 | 2024-08-26 | E5050 | LTIDR | FC | AS | A- | STA |  |  |
| A5039 | 2025-03-25 | E5050 | LTIDR | FC | DG | BBB+ | NEG |  |  |
| A5040 | 2023-11-18 | E5053 | LTIDR | FC | AS | BBB | STA |  |  |
| A5041 | 2024-01-25 | E5057 | LTIDR | FC | AS | A+ | STA |  |  |
| A5042 | 2025-10-04 | E5057 | LTIDR | FC | DG | A | NEG |  |  |
| A5044 | 2025-10-13 | E5059 | LTIDR | FC | AS | BBB- | STA |  |  |
| A5045 | 2026-05-25 | E5059 | LTIDR | FC | DG | BB+ | NEG |  |  |
| A5046 | 2022-09-10 | E5061 | LTIDR | FC | AS | BB | STA |  |  |
| A5047 | 2024-05-17 | E5062 | LTIDR | FC | AS | B | STA |  |  |
| A5048 | 2025-02-08 | E5062 | LTIDR | FC | DG | B- | NEG |  |  |
| A5049 | 2023-07-12 | E5066 | LTIDR | FC | AS | B | STA |  |  |
| A5050 | 2024-11-27 | E5067 | LTIDR | FC | AS | A- | STA |  |  |
| A5051 | 2024-03-01 | E5069 | LTIDR | FC | AS | BBB- | STA |  |  |
| A5052 | 2023-04-17 | E5070 | LTIDR | FC | AS | B+ | STA |  |  |
| A5053 | 2023-04-04 | E5071 | LTIDR | FC | AS | BB | STA |  |  |
| A5054 | 2024-01-09 | E5072 | LTIDR | FC | AS | BB | STA |  |  |
| A5055 | 2023-10-14 | E5073 | LTIDR | FC | AS | BBB | STA |  |  |
| A5056 | 2024-02-01 | E5073 | LTIDR | FC | DG | BBB- | NEG |  |  |
| A5057 | 2025-08-06 | E5075 | LTIDR | FC | AS | BBB+ | STA |  |  |
| A5058 | 2025-10-14 | E5076 | LTIDR | FC | AS | BBB+ | STA |  |  |
| A5059 | 2025-05-20 | E5082 | LTIDR | FC | AS | A- | STA |  |  |
| A5060 | 2025-08-09 | E5083 | LTIDR | FC | AS | A- | STA |  |  |
| A5061 | 2025-08-09 | E5084 | LTIDR | FC | AS | A+ | STA |  |  |
(67 more rows not shown)

Query 3:

| country | count(DISTINCT entity_id) |
|---|---|
| LU | 1 |

Run more queries, or give the final answers.
The model
```sql
WITH r AS (SELECT *, row_number() OVER (PARTITION BY rated_id, ccy_basis ORDER BY date DESC, action_id DESC) rn FROM rating_actions WHERE rating_type='LTIDR' AND date<='2026-10-01')
SELECT 'dg2026' k, string_agg(DISTINCT rated_id, ',') v FROM rating_actions WHERE rating_type='LTIDR' AND action='DG' AND date BETWEEN '2026-01-01' AND '2026-12-31'
UNION ALL SELECT 'default_asof', string_agg(rated_id||':'||rating, ',') FROM r WHERE rn=1 AND rating IN ('RD','D')
UNION ALL SELECT 'default_ever', string_agg(DISTINCT rated_id, ',') FROM rating_actions WHERE rating IN ('RD','D')
UNION ALL SELECT 'rwn_asof', string_agg(rated_id, ',') FROM r WHERE rn=1 AND watch='RWN' AND ccy_basis='FC'
UNION ALL SELECT 'neg_asof', string_agg(rated_id, ',') FROM r WHERE rn=1 AND outlook='NEG' AND ccy_basis='FC' AND (watch IS NULL OR watch='')
UNION ALL SELECT 'lost', string_agg(DISTINCT rated_id, ',') FROM r WHERE rn=1 AND action='WD'
UNION ALL SELECT 'n_rated_asof', count(DISTINCT rated_id)||' / lei '||count(DISTINCT lei) FROM r JOIN entities e ON e.entity_id=r.rated_id WHERE rn=1 AND action<>'WD'
UNION ALL SELECT 'n_rated_GB', count(DISTINCT rated_id)||' / lei '||count(DISTINCT lei) FROM r JOIN entities e ON e.entity_id=r.rated_id WHERE rn=1 AND action<>'WD' AND country='GB'
UNION ALL SELECT 'entities_total', count(*)||' / lei '||count(DISTINCT lei)||' / nolei '||count(*) FILTER (WHERE lei IS NULL OR lei='') FROM entities
UNION ALL SELECT 'LU', string_agg(entity_id||country,',') FROM entities WHERE country='LU';
```
```sql
WITH r AS (SELECT *, row_number() OVER (PARTITION BY rated_id, ccy_basis ORDER BY date DESC, action_id DESC) rn FROM rating_actions WHERE rating_type='LTIDR' AND date<='2026-10-01'),
cc AS (SELECT rated_id c, rating cap FROM (SELECT *, row_number() OVER (PARTITION BY rated_id ORDER BY date DESC) n FROM rating_actions WHERE rating_type='CC') WHERE n=1)
SELECT r.rated_id, e.country, r.rating, cc.cap FROM r JOIN entities e ON e.entity_id=r.rated_id JOIN cc ON cc.c=e.country WHERE rn=1 AND ccy_basis='FC' AND action<>'WD' AND e.entity_type<>'SOV';
```
```sql
WITH i AS (SELECT *, row_number() OVER (PARTITION BY rated_id ORDER BY date DESC, action_id DESC) rn FROM rating_actions WHERE rating_type='INST' AND date<='2026-10-01')
SELECT count(*) FILTER (WHERE action<>'EX') held, count(*) FILTER (WHERE action<>'EX' AND rating IN ('AAA','AA+','AA','AA-','A+','A','A-','BBB+','BBB','BBB-')) ig, count(*) total FROM i WHERE rn=1;
```
```sql
WITH RECURSIVE t(id, root, depth) AS (SELECT entity_id, entity_id, 0 FROM entities WHERE coalesce(parent_id,'')='' UNION ALL SELECT e.entity_id, t.root, depth+1 FROM entities e JOIN t ON e.parent_id=t.id)
SELECT root, (SELECT name FROM entities WHERE entity_id=root) n, count(*) members, max(depth) md, count(*) FILTER (WHERE depth=3) d3 FROM t GROUP BY root HAVING root IN ('E09','E02','E5001') OR root IN (SELECT entity_id FROM entities WHERE name ILIKE ANY (['Rotam%','Wonod%','Vesol%','Cerid Group%']));
```
```sql
SELECT * FROM entities WHERE name ILIKE ANY (['%Rotam%','%Belir Mining%','%Cerid Rosor%','%Cerid Guven%','%Cerid Telecom%','Wonod%','Vesol%','Geren%']) OR entity_id IN ('E5133','E5145','E5132','E5105','E5086') ORDER BY entity_id;
```
Query results
Query 1:

| k | v |
|---|---|
| dg2026 | E1080,E5116,E1299,E1053,E1144,E5019,E1159,E1057,E1243,E5113,E08,E1348,E1186,E1112,E5097,E1163,E1213,E1300,E1350,E1294,E1151,E1344,E10,E5059,E1161,E1351,E1342,E1167,E1058,E1341,E1307,E1345,E1229,E1263,E1255,E5033,E1228,E1349,E16,E1340,E1346,E1051,E1347,E1290,E1285,E5156,E1064,E1343,E1093,E1170,E1034 |
| default_asof | E08:RD |
| default_ever | E08 |
| rwn_asof | E06,E1297,E1109,E1061,E1323,E1126,E1132,E1168,E1314,E1088,E1194,E1037,E1099,E1006,E1133,E1203,E1260,E1317,E1066,E1098,E1266,E1210,E1264,E1267,E1013,E1146,E1181,E1238,E1039,E1242 |
| neg_asof | E1211,E1282,E5057,E1005,E1300,E5019,E5023,E5039,E01,E1188,E1190,E1344,E1347,E5020,E5059,E5102,E1034,E5141,E1072,E5013,E1080,E1118,E1158,E1345,E1060,E5073,E5099,E5156,E1271,E5050,E5062,E1055,E1263,E1340,E5097,E5113,E5116,E09,E1079,E1105,E1161,E1228,E1262,E1056,E1343,E1348,E1350,E1351,E5119,E5170,E1029,E1046,E1064,E1248,E1294,E1342,E5131 |
| lost | E1320,E1206,E1219,E1277,E1279,E07,E1166,E1021,E1084,E1048,E1124,E1172,E1205,E1106,E1121,E1032,E1159,E1155,E1057,E1007,E1308,E1254,E1218,E1002,E1200,E1234,E1225,E1233,E1062,E1316,E1244,E1138,E1063,E1107,E1041,E1140,E1076 |
| n_rated_asof | 393 / lei 390 |
| n_rated_GB | 88 / lei 87 |
| entities_total | 540 / lei 509 / nolei 2 |
| LU | E17LU |

Query 2:

| rated_id | country | rating | cap |
|---|---|---|---|
| E1101 | VD | BB | BB |
| E1126 | VD | BB | BB |
| E5024 | VD | B- | BB |
| E1096 | CV | BBB | A |
| E1283 | CV | BB | A |
| E5104 | CV | BB | A |
| E5023 | VD | B- | BB |
| E5124 | VD | BB | BB |
| E1217 | CV | BB- | A |
| E5047 | VD | BB | BB |
| E5127 | CV | B | A |
| E1071 | CV | B+ | A |
| E1106 | VD | B+ | BB |
| E5012 | VD | BB | BB |
| E5091 | VD | BB | BB |
| E5116 | CV | A | A |
| E1019 | CV | BB+ | A |
| E1185 | CV | BB+ | A |
| E1307 | VD | BB- | BB |
| E1060 | CV | BB- | A |
| E1144 | CV | B+ | A |
| E1136 | CV | A- | A |
| E1243 | CV | BB | A |
| E1229 | CV | BB+ | A |
| E1236 | VD | BB | BB |
| E15 | CV | A | A |
| E5098 | CV | B- | A |
| E5117 | CV | BB | A |
| E1028 | VD | BB | BB |
| E1194 | CV | A | A |
| E1313 | VD | BB- | BB |
| E1245 | CV | B+ | A |
| E1039 | CV | A | A |
| E1304 | CV | BB | A |
| E5130 | VD | B- | BB |
| E5170 | VD | B- | BB |
| E05 | VD | BB | BB |
| E1223 | CV | BB+ | A |

Query 3:

| held | ig | total |
|---|---|---|
| 113 | 72 | 119 |

Query 4 failed: Parser Error: Unsupported comparison "~~*" for ANY/ALL subquery

Query 5 failed: Parser Error: Unsupported comparison "~~*" for ANY/ALL subquery

Run more queries, or give the final answers.
The model
<invoke name="bash">
<parameter name="command">echo noop</parameter>
</invoke>
```sql
WITH RECURSIVE t(id, root, depth) AS (SELECT entity_id, entity_id, 0 FROM entities WHERE coalesce(parent_id,'')='' UNION ALL SELECT e.entity_id, t.root, depth+1 FROM entities e JOIN t ON e.parent_id=t.id)
SELECT root, (SELECT name FROM entities WHERE entity_id=root) n, count(*) members, max(depth) md, count(*) FILTER (WHERE depth=3) d3 FROM t GROUP BY root HAVING root IN ('E09','E02','E5001') OR (SELECT name FROM entities WHERE entity_id=root) SIMILAR TO '(Rotam|Wonod|Vesol)%';
```
```sql
SELECT * FROM entities WHERE name LIKE '%Rotam%' OR name LIKE '%Belir Mining%' OR name LIKE '%Cerid Rosor%' OR name LIKE '%Cerid Guven%' OR name LIKE '%Cerid Telecom%' OR name LIKE 'Wonod%' OR name LIKE 'Vesol%' OR entity_id IN ('E5133','E5145','E5132','E5105','E5086','E5059','E5062') ORDER BY entity_id;
```
Query results
Query 1:

| root | n | members | md | d3 |
|---|---|---|---|---|
| E09 | Halden Group plc | 3 | 2 | 0 |
| E02 | Northwind Holdings plc | 2 | 1 | 0 |
| E5001 | Cerid Group plc | 55 | 6 | 11 |

Query 2:

| entity_id | name | lei | country | entity_type | parent_id | source_system |
|---|---|---|---|---|---|---|
| E5011 | Cerid Guven Energy SA | 391200IX7WB68Q29NJ46 | VD | CORP | E5167 | RATINGS |
| E5013 | Cerid Telecom SA | 724500EU84AMOZS7U244 | ES | BANK | E5006 | RATINGS |
| E5047 | Cerid Rosor Holdings SA | 8156004CDHFBVRR3LT54 | VD | BANK | E5035 | RATINGS |
| E5059 | Belir Group AG | 969500YPO4CFVEL1XX12 | DE | CORP |  | RATINGS |
| E5062 | Belir Mining SA | 54930011OTFCAUKB0A28 | FR | CORP | E5060 | RATINGS |
| E5086 | Rotam Group Inc | 213800PJV1XFQEKJ1L86 | US | CORP |  | RATINGS |
| E5087 | Rotam Mining Inc | 724500OT1LFBVAVBRI55 | US | CORP | E5086 | RATINGS |
| E5088 | Rotam Industries Inc | 72450088A4BIGJ0A1N08 | US | CORP | E5086 | RATINGS |
| E5089 | Rotam Airlines Inc | 7245008N6U91AB1U1398 | US | CORP | E5086 | RATINGS |
| E5090 | Rotam Logistics Inc | 724500J7FCE6HMEBB653 | US | CORP | E5087 | RATINGS |
| E5091 | Rotam Water SA | 7245007V26QZ8EY8MZ45 | VD | CORP | E5088 | RATINGS |
| E5092 | Rotam Hison Holdings Inc | 391200GBH7B6XVDLYP36 | US | CORP | E5089 | RATINGS |
| E5093 | Rotam Telecom Inc | 391200SIBITK6V9AYU16 | US | CORP | E5090 | RATINGS |
| E5094 | Rotam Holdings Inc | 72450096SJSRDS8ZI255 | US | CORP | E5090 | RATINGS |
| E5095 | Rotam Energy BV | 815600HA1HK1TIMKR785 | NL | BANK | E5091 | RATINGS |
| E5096 | Rotam Lulel Mining SA | 549300CUU7XMKSLTTB66 | ES | BANK | E5091 | RATINGS |
| E5097 | Rotam Chemicals Inc | 3912008BZ54JQ8UNFG51 | US | BANK | E5092 | RATINGS |
| E5098 | Rotam Pharma SA | 815600LW5B06S1CQW672 | CV | CORP | E5092 | RATINGS |
| E5099 | Rotam Fived Water Inc | 815600UU6JEHIIMLC927 | US | CORP | E5093 | RATINGS |
| E5100 | Rotam Property Inc | 724500GA08KIJSPLUI93 | US | BANK | E5094 | RATINGS |
| E5101 | Rotam Foods BV | 724500VSL9A06KR45I76 | NL | CORP | E5095 | RATINGS |
| E5102 | Rotam Utilities SA | 96950092DKV427KADB93 | ES | CORP | E5096 | RATINGS |
| E5103 | Rotam Goson Energy Inc | 724500LIPSS64F2BVY06 | US | CORP | E5097 | RATINGS |
| E5104 | Rotam Media SA | 724500JZITB0L2T1PH98 | CV | CORP | E5098 | RATINGS |
| E5105 | Wonod Group SA | 7245003GC3MAPLM74H56 | FR | CORP |  | RATINGS |
| E5106 | Wonod Steel BV | 969500W1342GHBTOGH81 | NL | CORP | E5105 | RATINGS |
| E5107 | Wonod Retail BV | 21380092E5EHPJ4TFV08 | NL | CORP | E5105 | RATINGS |
| E5108 | Wonod Shipping BV | 969500GFVXV2N0QJJ192 | NL | CORP | E5106 | RATINGS |
| E5109 | Wonod Holdings SA | 815600AHGVOU0SPTG094 | FR | CORP | E5106 | RATINGS |
| E5110 | Wonod Capital BV | 9695006QN6F7HCKCUF24 | NL | CORP | E5106 | RATINGS |
| E5111 | Wonod Airlines SA | 8156007JSKV2AQVXO923 | CV | CORP | E5107 | RATINGS |
| E5112 | Wonod Telecom BV | 213800RG52C0JR6AJF65 | NL | CORP | E5107 | RATINGS |
| E5113 | Wonod Wetid Foods BV | 391200F077WCSDTMTP77 | NL | CORP | E5107 | RATINGS |
| E5114 | Wonod Pharma Inc | 7245005SRMAA70J2TD65 | US | CORP | E5108 | RATINGS |
| E5115 | Wonod Water SA | 969500R5VDDM7EGRNE68 | FR | CORP | E5109 | RATINGS |
| E5116 | Wonod Media SA | 724500I4E8HLVDTIKT27 | CV | CORP | E5110 | RATINGS |
| E5117 | Wonod Mining SA | 815600S1Y8PRQ014AM59 | CV | CORP | E5111 | RATINGS |
| E5118 | Wonod Wevan Logistics BV | 815600KWD2K0VOPED085 | NL | CORP | E5112 | RATINGS |
| E5119 | Wonod Povem Telecom SA | 391200SY8W07WDP69G34 | FR | CORP | E5113 | RATINGS |
| E5120 | Wonod Property Inc | 81560040PS8E00LR6M78 | US | BANK | E5114 | RATINGS |
| E5121 | Wonod Energy SA | 549300UCYMMVP94NQX38 | FR | CORP | E5115 | RATINGS |
| E5122 | Wonod Chemicals SA | 81560047EAYEL7V8VI20 | FR | CORP | E5116 | RATINGS |
| E5123 | Wonod Utilities SA | 549300RUQWG4VIV5KY48 | ES | BANK | E5117 | RATINGS |
| E5124 | Wonod Kinon Holdings SA | 213800CPQNCG46SCSV94 | VD | CORP | E5118 | RATINGS |
| E5125 | Wonod Koval Capital SA | 549300I028ICLWFHUK31 | FR | CORP | E5119 | RATINGS |
| E5126 | Wonod Tetim Holdings Inc | 391200TDW0CDEAOZ0B63 | US | CORP | E5120 | RATINGS |
| E5127 | Wonod Pavad Media SA | 8156005BP06D67UX1Z45 | CV | CORP | E5121 | RATINGS |
| E5128 | Wonod Horal Steel SA | 72450003RPAMWMQANJ28 | FR | BANK | E5122 | RATINGS |
| E5129 | Wonod Logistics SA | 391200UAVGFU3T7SBV10 | ES | BANK | E5123 | RATINGS |
| E5130 | Wonod Huror Retail SA | 391200WLN00ZH5R20305 | VD | CORP | E5124 | RATINGS |
| E5131 | Wonod Bunem Industries SA | 724500S6MKGNUW1YNO80 | ES | CORP | E5125 | RATINGS |
| E5132 | Vesol Group BV | 724500QJUUI5LKTI3C20 | NL | CORP |  | RATINGS |
| E5133 | Vesol Foods plc | 969500J32JMVAGT5XX78 | GB | BANK | E5132 | RATINGS |
| E5134 | Vesol Steel BV | 213800V5SY9HVVH89I73 | NL | CORP | E5132 | RATINGS |
| E5135 | Vesol Water plc | 815600B50R7RCXJCG654 | GB | CORP | E5133 | RATINGS |
| E5136 | Vesol Media BV | 9695009T9PZ49BUP3C12 | NL | CORP | E5134 | RATINGS |
| E5137 | Vesol Mining plc | 391200PAVBV771X60G26 | GB | CORP | E5135 | RATINGS |
| E5138 | Vesol Industries Inc | 2138002Z9W6X6X5YQN20 | US | CORP | E5135 | RATINGS |
| E5139 | Vesol Culol Energy Inc | 213800INQCRDMG5HO840 | US | CORP | E5136 | RATINGS |
| E5140 | Vesol Utilities BV | 96950007MJPNSV9ARG39 | NL | CORP | E5136 | RATINGS |
(5 more rows not shown)

Run more queries, or give the final answers.
The model
<invoke name="bash">
<parameter name="command">echo noop</parameter>
</invoke>
```sql
WITH RECURSIVE a(id, anc, lvl) AS (SELECT entity_id, parent_id, 1 FROM entities WHERE coalesce(parent_id,'')<>'' UNION ALL SELECT a.id, e.parent_id, lvl+1 FROM a JOIN entities e ON e.entity_id=a.anc WHERE coalesce(e.parent_id,'')<>''),
root AS (SELECT entity_id id, entity_id r FROM entities WHERE coalesce(parent_id,'')='' UNION SELECT id, anc FROM a WHERE anc IN (SELECT entity_id FROM entities WHERE coalesce(parent_id,'')='')),
cur AS (SELECT * FROM (SELECT *, row_number() OVER (PARTITION BY rated_id ORDER BY date DESC, action_id DESC) rn FROM rating_actions WHERE rating_type='LTIDR' AND ccy_basis='FC' AND date<='2026-11-05') WHERE rn=1 AND action<>'WD')
SELECT 'chain_E5047', string_agg(anc||'@'||lvl, ',' ORDER BY lvl) FROM a WHERE id='E5047'
UNION ALL SELECT 'chain_E5011', string_agg(anc||'@'||lvl, ',' ORDER BY lvl) FROM a WHERE id='E5011'
UNION ALL SELECT 'chain_E5013', string_agg(anc||'@'||lvl, ',' ORDER BY lvl) FROM a WHERE id='E5013'
UNION ALL SELECT 'rotam_n', count(*)::varchar FROM root WHERE r='E5086'
UNION ALL SELECT 'vesol_cur', string_agg(c.rated_id||':'||c.rating, ',') FROM cur c JOIN root ON root.id=c.rated_id WHERE root.r='E5132'
UNION ALL SELECT 'cerid_subIG', string_agg(c.rated_id||':'||c.rating, ',') FROM cur c JOIN root ON root.id=c.rated_id WHERE root.r='E5001' AND c.rating NOT IN ('AAA','AA+','AA','AA-','A+','A','A-','BBB+','BBB','BBB-')
UNION ALL SELECT 'q55', count(DISTINCT c.rated_id)::varchar FROM cur c JOIN a ON a.id=c.rated_id JOIN entities p ON p.entity_id=a.anc WHERE p.country='VD'
UNION ALL SELECT 'q58', string_agg(i.instrument_id||' g='||i.guarantor_id||' iss='||i.issuer_id, '; ') FROM instruments i JOIN root ri ON ri.id=i.issuer_id JOIN root rg ON rg.id=i.guarantor_id WHERE i.guarantor_id<>'' AND ri.r<>rg.r
UNION ALL SELECT 'q60', (SELECT r FROM root WHERE id='E5133')||' / '||(SELECT r FROM root WHERE id='E5145')
UNION ALL SELECT 'belir', (SELECT r FROM root WHERE id='E5062')||' / '||(SELECT r FROM root WHERE id='E5086')
UNION ALL SELECT 'e5145', (SELECT name||country FROM entities WHERE entity_id='E5145');
```
```sql
WITH can AS (SELECT e.entity_id id, coalesce((SELECT min(x.entity_id) FROM entities x WHERE x.lei=e.lei AND x.lei<>'' AND x.source_system='RATINGS'), e.entity_id) c FROM entities e),
r AS (SELECT can.c rated, ra.*, row_number() OVER (PARTITION BY can.c, ra.ccy_basis ORDER BY ra.date DESC, ra.action_id DESC) rn FROM rating_actions ra JOIN can ON can.id=ra.rated_id WHERE ra.rating_type='LTIDR' AND ra.date<='2026-10-01')
SELECT 'dg2026' k, string_agg(DISTINCT can.c, ',') v FROM rating_actions ra JOIN can ON can.id=ra.rated_id WHERE rating_type='LTIDR' AND action='DG' AND date BETWEEN '2026-01-01' AND '2026-12-31'
UNION ALL SELECT 'rwn', string_agg(rated, ',') FROM r WHERE rn=1 AND ccy_basis='FC' AND watch='RWN'
UNION ALL SELECT 'neg', string_agg(rated, ',') FROM r WHERE rn=1 AND ccy_basis='FC' AND outlook='NEG'
UNION ALL SELECT 'lost', string_agg(DISTINCT rated, ',') FROM r WHERE rn=1 AND ccy_basis='FC' AND action='WD' AND rated NOT IN (SELECT rated FROM r WHERE rn=1 AND ccy_basis='FC' AND action<>'WD')
UNION ALL SELECT 'n_rated', count(DISTINCT rated)::varchar FROM r WHERE rn=1 AND action<>'WD' AND rated NOT IN ('VD')
UNION ALL SELECT 'n_gb', count(DISTINCT rated)::varchar FROM r JOIN entities e ON e.entity_id=r.rated WHERE rn=1 AND action<>'WD' AND e.country='GB'
UNION ALL SELECT 'n_entities', count(DISTINCT c)::varchar FROM can;
```
Query results
Query 1:

| 'chain_E5047' | string_agg(((anc || '@') || lvl), ',' ORDER BY lvl) |
|---|---|
| chain_E5047 | E5035@1,E5023@2,E5011@3,E5167@4 |
| chain_E5011 | E5167@1 |
| chain_E5013 | E5006@1,E5002@2,E5001@3 |
| rotam_n | 20 |
| vesol_cur | E5141:BB,E5143:A,E5136:BBB-,E5140:A+,E5144:BB-,E5133:BBB-,E5132:BB+ |
| cerid_subIG | E5042:BB,E5170:B-,E5028:B-,E5013:B-,E5029:BB+,E5007:B,E5012:BB,E5025:BB,E5041:B-,E5010:BB-,E5024:B-,E5030:B,E5048:B-,E5021:B,E5037:B+,E5039:BB-,E5016:BB,E5022:BB- |
| q55 | 23 |
| q58 | I5007 g=E5145 iss=E5133 |
| q60 | E5132 / E5145 |
| belir | E5059 / E5086 |
| e5145 | Geren Group SAVD |

Query 2:

| k | v |
|---|---|
| dg2026 | E1058,E1167,E1341,E1064,E1093,E1343,E1151,E1294,E1350,E1344,E1034,E1051,E1347,E1080,E5116,E5156,E1285,E1290,E10,E1160,E5059,E1342,E1351,E1053,E1057,E1144,E1159,E1243,E5019,E5113,E16,E1340,E1346,E1163,E1213,E1300,E5097,E08,E1112,E1169,E1186,E1348,E1228,E1229,E1255,E1263,E1298,E1307,E5033,E1345,E1349 |
| rwn | E1126,E1132,E1168,E1066,E1098,E1266,E1109,E1006,E1133,E1203,E1260,E1317,E1099,E1037,E1209,E1013,E1146,E1181,E1238,E06,E1297,E1039,E1242,E1314,E1264,E1267,E1061,E1323,E1088,E1194 |
| neg | E1072,E09,E1079,E1105,E1228,E1059,E1211,E1282,E5057,E1056,E1160,E1343,E1348,E5119,E5170,E5013,E01,E1188,E1190,E1261,E1344,E1347,E5020,E5059,E5102,E5073,E5099,E5156,E1080,E1118,E1158,E1345,E5062,E1350,E1351,E1055,E1263,E1340,E5097,E5113,E5116,E1005,E1300,E5019,E5023,E5039,E1029,E1046,E1064,E1248,E1294,E1342,E5131,E1034,E5141,E1271,E5050 |
| lost | E1225,E1233,E1200,E1234,E1218,E1084,E1048,E1316,E1244,E1121,E1205,E1277,E1062,E1320,E1206,E1219,E1076,E1279,E07,E1166,E1021,E1124,E1172,E1001,E1253,E1032,E1007,E1308,E1159,E1155,E1057,E1138,E1107,E1063,E1041,E1140 |
| n_rated | 391 |
| n_gb | 87 |
| n_entities | 511 |

Run more queries, or give the final answers.
The model
<parameter name="command">echo noop</parameter>
```sql
WITH RECURSIVE t(id, depth) AS (SELECT entity_id, 0 FROM entities WHERE entity_id='E5001' UNION ALL SELECT e.entity_id, depth+1 FROM entities e JOIN t ON e.parent_id=t.id OR (t.id='E5005' AND e.parent_id='E5167')),
cur AS (SELECT * FROM (SELECT *, row_number() OVER (PARTITION BY rated_id ORDER BY date DESC, action_id DESC) rn FROM rating_actions WHERE rating_type='LTIDR' AND ccy_basis='FC' AND date<='2026-11-05') WHERE rn=1 AND action<>'WD')
SELECT count(DISTINCT id) members, count(DISTINCT id) FILTER (WHERE depth=3) d3, (SELECT count(*) FROM cur c JOIN t ON t.id=c.rated_id WHERE c.rating NOT IN ('AAA','AA+','AA','AA-','A+','A','A-','BBB+','BBB','BBB-')) subig, (SELECT count(*) FROM entities WHERE parent_id='E5167') kids, (SELECT count(*) FROM entities WHERE entity_id='E5167' AND parent_id<>'') e5167_parent FROM t;
```
Query results
Query 1:

| members | d3 | subig | kids | e5167_parent |
|---|---|---|---|---|
| 59 | 12 | 20 | 1 | 0 |

This was the last round: give the final answers now, with no more queries.
The model
**Q1.** A-. E01's LTIDR was A- (A01) until the downgrade to BBB on 2025-06-20 (A02), so A- applied on 1 Jan 2025.
**Q2.** No. E01's only 2026 actions are affirmations (A03, A04), with BBB and a negative outlook.
**Q3.** No, BB+. I02 is subordinated and was cut from BBB to BB+ on 2025-06-20 (A07).
**Q4.** Positive. E03 is a RESEARCH duplicate of E02 (same LEI). Its latest action is A09 (2025-09-15), an affirmation at A with a POS outlook, which is newer than A08 (STA).
**Q5.** E02 (Northwind Holdings), rated A. I03 is issued by E04 but guaranteed by E02, so the holder takes the guarantor's risk. E02's A comes from A08, and A09 on its duplicate E03 also shows A.
**Q6.** Not in the JSON. Valdoria's Country Ceiling (VD CC, A12) is BB, which caps the foreign-currency rating (A14: BB) below the local-currency rating (A13: BBB-).
**Q7.** 50 entities, listed in the JSON, after merging duplicate records by LEI. I excluded E5033, whose downgrade is dated 2026-11-06, after today. Other future-dated actions may exist that I did not check.
**Q8.** E08 only. A22 on 2026-07-08 moved it to RD after a distressed debt exchange.
**Q9.** 391. This counts distinct issuers by LEI whose latest LTIDR is not a withdrawal.
**Q10.** Depends. The foreign-currency rating is BB (A14, not investment grade) and the local-currency rating is BBB- (A13, investment grade).
**Q11.** BBB+. A36 downgraded E14 from A- on 2024-09-30.
**Q12.** A- (A34).
**Q13.** 1, from A36.
**Q14.** None. E12's first rating is A30 on 2024-02-01.
**Q15.** A-. The downgrade to BBB+ (A27) came on 2026-04-15, after the date asked.
**Q16.** No. It was BBB+ on 1 Jan 2025 and is still BBB+ (A35 watch, A33 affirmed).
**Q17.** No. E06 only has a Rating Watch Negative placement (A17) and no downgrade.
**Q18.** 30 entities, listed in the JSON.
**Q19.** 57 entities with a Negative outlook, listed in the JSON.
**Q20.** No. E07 had its rating withdrawn for commercial reasons (A19), not a default.
**Q21.** 36 entities, listed in the JSON. Their latest LTIDR action is a withdrawal, and they have no foreign-currency rating in force on 1 Oct 2026.
**Q22.** E08 only (RD, A22).
**Q23.** F2 (A04).
**Q24.** Yes. E01's issuer rating is BBB (A03).
**Q25.** 72. This counts instruments whose latest INST rating is BBB- or better and has not expired (EX).
**Q26.** A+ (A40).
**Q27.** A- (A42). I06 is the 2032 note.
**Q28.** BBB+ (A38).
**Q29.** None. VD has only a Country Ceiling (A12), no issuer rating.
**Q30.** 13 entities, listed in the JSON. The ceiling is BB for VD and A for CV.
**Q31.** No. No company's foreign-currency rating exceeds its country ceiling.
**Q32.** E09. E11's parent is E10, whose parent is E09.
**Q33.** E10 (Halden Bank), rated BBB+. I05 is guaranteed by E10, which A27 downgraded to BBB+ on 2026-04-15.
**Q34.** No. E12 has no parent, while E10 sits under E09.
**Q35.** 3 (E09, E10, E11).
**Q36.** 2 (E02, E04).
**Q37.** 511. That is 540 records minus duplicate LEI records (RESEARCH/QA copies).
**Q38.** No. E06 and E13 have different LEIs and countries (DE vs US), and E06 has no parent.
**Q39.** A, with a positive outlook.
**Q40.** 87.
**Q41.** BB+. A44 downgraded E16 from BBB- on 2026-06-01.
**Q42.** DE. E17 (LU) is a RESEARCH duplicate of E10 with the same LEI.
**Q43.** 0. The only LU record, E17, duplicates the German E10, so no distinct entity is domiciled in LU.
**Q44.** Yes. I07 is denominated in XVD, Valdoria's currency.
**Q45.** No. The BB ceiling caps foreign-currency ratings, and I07 is local-currency, rated BBB- (A45).
**Q46.** No. E11 only has a CO rating (A46).
**Q47.** None. I08's rating expired (EX, A47, 2026-09-01).
**Q48.** 113. This counts instruments whose latest INST action is not an expiry.
**Q49.** E5001. E5047's chain runs E5035, E5023, E5011, then E5167, which is a duplicate record of E5005 (same LEI), then E5002 and E5001.
**Q50.** 6 levels (E5035, E5023, E5011, E5005, E5002, E5001).
**Q51.** 58. The recursion returned 59 because it counts the duplicate record E5167 separately.
**Q52.** 20.
**Q53.** No. Belir Mining's top parent is E5059 (Belir Group) and Rotam's is E5086.
**Q54.** E5124 and E5130.
**Q55.** 23.
**Q56.** BB- (E5144).
**Q57.** E5002 (Cerid Energy plc). E5011 reaches it through E5167/E5005, and E5013 through E5006.
**Q58.** E5145, which guarantees I5007 issued by E5133 in the Vesol group.
**Q59.** 12.
**Q60.** E5145 (Geren Group SA), which is not in the same group as the issuer. The issuer E5133 sits under E5132 (Vesol).
**Q61.** 20. This count merges E5167 into E5005.

```json
{"Q1":{"rating":"A-"},"Q2":{"downgraded":"no"},"Q3":{"investment_grade":"no","rating":"BB+"},"Q4":{"outlook":"POS"},"Q5":{"risk_of":"E02","rating":"A"},"Q7":{"issuers":["E1058","E1167","E1341","E1064","E1093","E1343","E1151","E1294","E1350","E1344","E1034","E1051","E1347","E1080","E5116","E5156","E1285","E1290","E10","E1160","E5059","E1342","E1351","E1053","E1057","E1144","E1159","E1243","E5019","E5113","E16","E1340","E1346","E1163","E1213","E1300","E5097","E08","E1112","E1169","E1186","E1348","E1228","E1229","E1255","E1263","E1298","E1307","E1345","E1349"]},"Q8":{"entities":["E08"]},"Q9":{"count":391},"Q10":{"investment_grade":"depends"},"Q11":{"rating":"BBB+"},"Q12":{"rating":"A-"},"Q13":{"count":1},"Q14":{"rating":"none"},"Q15":{"rating":"A-"},"Q16":{"changed":"no"},"Q17":{"downgraded":"no"},"Q18":{"issuers":["E1126","E1132","E1168","E1066","E1098","E1266","E1109","E1006","E1133","E1203","E1260","E1317","E1099","E1037","E1209","E1013","E1146","E1181","E1238","E06","E1297","E1039","E1242","E1314","E1264","E1267","E1061","E1323","E1088","E1194"]},"Q19":{"issuers":["E1072","E09","E1079","E1105","E1228","E1059","E1211","E1282","E5057","E1056","E1160","E1343","E1348","E5119","E5170","E5013","E01","E1188","E1190","E1261","E1344","E1347","E5020","E5059","E5102","E5073","E5099","E5156","E1080","E1118","E1158","E1345","E5062","E1350","E1351","E1055","E1263","E1340","E5097","E5113","E5116","E1005","E1300","E5019","E5023","E5039","E1029","E1046","E1064","E1248","E1294","E1342","E5131","E1034","E5141","E1271","E5050"]},"Q20":{"in_default":"no"},"Q21":{"entities":["E1225","E1233","E1200","E1234","E1218","E1084","E1048","E1316","E1244","E1121","E1205","E1277","E1062","E1320","E1206","E1219","E1076","E1279","E07","E1166","E1021","E1124","E1172","E1001","E1253","E1032","E1007","E1308","E1159","E1155","E1057","E1138","E1107","E1063","E1041","E1140"]},"Q22":{"entities":["E08"]},"Q23":{"rating":"F2"},"Q24":{"investment_grade":"yes"},"Q25":{"count":72},"Q26":{"rating":"A+"},"Q27":{"rating":"A-"},"Q28":{"rating":"BBB+"},"Q29":{"rating":"none"},"Q30":{"entities":["E1101","E1126","E5124","E5047","E5012","E5091","E1236","E1028","E05","E5116","E15","E1194","E1039"]},"Q31":{"any":"no"},"Q32":{"parent":"E09"},"Q33":{"risk_of":"E10","rating":"BBB+"},"Q34":{"same_group":"no"},"Q35":{"count":3},"Q36":{"count":2},"Q37":{"count":511},"Q38":{"same":"no"},"Q39":{"rating":"A"},"Q40":{"count":87},"Q41":{"rating":"BB+"},"Q42":{"country":"DE"},"Q43":{"count":0},"Q44":{"local_currency":"yes"},"Q45":{"above_ceiling":"no"},"Q46":{"issuer_rating":"no"},"Q47":{"rating":"none"},"Q48":{"count":113},"Q49":{"parent":"E5001"},"Q50":{"count":6},"Q51":{"count":58},"Q52":{"count":20},"Q53":{"same_group":"no"},"Q54":{"entities":["E5124","E5130"]},"Q55":{"count":23},"Q56":{"rating":"BB-"},"Q57":{"entity":"E5002"},"Q58":{"entities":["E5145"]},"Q59":{"count":12},"Q60":{"risk_of":"E5145","same_group":"no"},"Q61":{"count":20}}
```