Leetcode Problem 1193. Monthly Transactions I

1193. Monthly Transactions I

Leetcode Solutions

Aggregating Monthly Transaction Data by Country

Algorithm

  1. Use the DATE_FORMAT function to extract the year and month from the trans_date column and alias it as month.
  2. Select the country column as is.
  3. Use the COUNT function to count the total number of transactions for each group and alias it as trans_count.
  4. Use the SUM function with a CASE WHEN expression to count the number of approved transactions and alias it as approved_count.
  5. Use the SUM function to calculate the total amount of transactions for each group and alias it as trans_total_amount.
  6. Use the SUM function with a CASE WHEN expression to calculate the total amount of approved transactions and alias it as approved_total_amount.
  7. Group the results by the formatted month and country.

erDiagram
    Transactions {
        int id PK
        varchar country
        enum state
        int amount
        date trans_date
    }

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...