Credit and Debit Transaction Counts per User
Problem statement
For every user appearing in the transaction table, count Credit and Debit transactions separately.
Return user_id, credit_count, and debit_count, including zero for a missing type.
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.
transactions
| Column | Type | Nullable | Description |
|---|---|---|---|
| transaction_idPK | Integer | No | — |
| user_id | Integer | No | — |
| transaction_type | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| user_id | Integer | No | — |
| credit_count | Integer | No | — |
| debit_count | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
transaction_typeis exactlyCreditorDebit.- Each transaction counts once.
- Sort users by ID ascending.