Bond Interest Summary Above 3%
Problem statement
The bonds table lists bonds. The interest_rates table holds the interest rates recorded for each bond, written as percentages: 3.25 means 3.25%. A bond can have many rates.
For each bond whose average interest rate is above 3%, return bond_id, bond_name, highest_interest, average_interest, and lowest_interest.
- Use all of a bond's rates for all three values. A rate that appears twice counts twice.
- Check the 3% rule against the exact average. A bond whose exact average is exactly
3is left out. - Round
average_interestto two decimal places, with halves rounded away from zero. - A bond with no rates is left out.
Sort the rows by bond_id from smallest to largest.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
bonds
| Column | Type | Nullable | Description |
|---|---|---|---|
| bond_idPK | Integer | No | — |
| bond_name | Text | No | — |
interest_rates
| Column | Type | Nullable | Description |
|---|---|---|---|
| rate_idPK | Integer | No | — |
| bond_id | Integer | No | — |
| interest_rate | Decimal | No | — |
Foreign key: bond_id → bonds(bond_id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| bond_id | Integer | No | — |
| bond_name | Text | No | — |
| highest_interest | Decimal | No | — |
| average_interest | Decimal | No | — |
| lowest_interest | Decimal | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
bond_idis a unique positive integer inbonds, andrate_idis a unique positive integer ininterest_rates.- Every
interest_rates.bond_idexists inbonds. interest_rateis from0.00to100.00, with at most two decimal places. No value is null.- Two bonds can have the same
bond_name. They are still separate bonds. - Each table has at most
2000rows.