All problems

What Kinds of Transactions Are Customers Making?

easySQLGroupBy

Northline Bank's operations team is planning capacity for the next quarter and wants to see the shape of the month's traffic: how many transactions of each kind the systems handled, as raw counts.

Each transaction carries a type label. The team wants the answer built from whatever labels actually appear in the data, so that a kind they have not thought of — a fee, a reversal — turns up on the list by itself instead of being quietly left out.

transactions — one row per transaction. amount is in dollars and is negative for money leaving the account. type is a short label.

id customer_id amount type txn_date
1 1 500 deposit 2023-07-01
2 1 -120 withdrawal 2023-07-03
3 2 1000 deposit 2023-07-02
4 2 -300 withdrawal 2023-07-05
5 3 250 deposit 2023-07-04
6 3 -600 withdrawal 2023-07-06
7 4 800 deposit 2023-07-07
8 4 -450 withdrawal 2023-07-08
9 5 2000 deposit 2023-07-09
10 5 -1500 withdrawal 2023-07-10
11 1 -200 transfer 2023-07-11
12 3 400 deposit 2023-07-12

The table already exists in the database — there is nothing to create or load.

Task: Write a query returning two columns, type and num_txns, with one row for every label that appears in the table. A label no transaction carries produces no row. Rows come back in alphabetical order of type.

Example output — shape only; the figures below are invented, not this data's answer.

type num_txns
deposit 9
transfer 3
withdrawal 12

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…