SQL MOSAIC #1193. Monthly Transactions I

Summer Nie
Jul 5, 2022

Date:7/5/2022

Thinking Pathway:

  1. DATE_FORMAT() Function

Solution(s):

SELECT DATE_FORMAT(trans_date, ‘%Y-%m’) AS month,
country,
COUNT(id) AS trans_count,
SUM(
CASE WHEN state = ‘approved’ THEN 1
ELSE 0
END) AS approved_count,
SUM(amount) AS trans_total_amount,
SUM(
CASE WHEN state = ‘approved’ THEN amount
ELSE 0
END) AS approved_total_amount

FROM Transactions t

GROUP BY month, country

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response