Block Transaction Count Trends
Problem statement
The btc_blocks table records one Bitcoin block per row with its height and transaction count.
For every block, show its block_height, current transaction_count, and the preceding block row's transaction count as previous_transaction_count. Add a trend label: Increased, Decreased, or Same by comparing the current count with the previous count.
Order rows by block_height ascending. For the earliest block, return NULL as the previous count and Same as the trend.
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.
btc_blocks
Bitcoin blocks and their transaction counts.
| Column | Type | Nullable | Description |
|---|---|---|---|
| block_heightPK | Integer | No | Unique Bitcoin block height. |
| transaction_count | Integer | No | Number of transactions in the block. |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| block_height | Integer | No | — |
| transaction_count | Integer | No | — |
| previous_transaction_count | Integer | Yes | — |
| trend | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
btc_blockscontains from 1 through 2,000 rows.block_heightis a unique nonnegative integer.transaction_countis a nonnegative integer.- The previous block means the preceding available row after sorting by
block_height, even when heights are not consecutive.