6 kyu
Conditional Count
7,542 of 7,545pmatseykanets
Description:
Given a payment
table, which is a part of DVD Rental Sample Database, with the following schema
Column | Type | Modifiers
-------------+-----------------------------+----------
payment_id | integer | not null
customer_id | smallint | not null
staff_id | smallint | not null
rental_id | integer | not null
amount | numeric(5,2) | not null
payment_date | timestamp without time zone | not null
produce a result set for the report that shows a side-by-side comparison of the number and total amounts of payments made in Mike's and Jon's stores broken down by months.
The resulting data set should be ordered by month
using natural order (Jan, Feb, Mar, etc.).
Note: You don't need to worry about the year component. Months are never repeated because the sample data set contains payment information only for one year.
The desired output for the report
month | total_count | total_amount | mike_count | mike_amount | jon_count | jon_amount
------+-------------+--------------+------------+-------------+-----------+-----------
2 | | | | | |
5 | | | | | |
...
month
- number of the month (1 - January, 2 - February, etc.)total_count
- total number of paymentstotal_amount
- total payment amountmike_count
- total number of payments accepted by Mike (staff_id = 1
)mike_amount
- total amount of payments accepted by Mike (staff_id = 1
)jon_count
- total number of payments accepted by Jon (staff_id = 2
)jon_amount
- total amount of payments accepted by Jon (staff_id = 2
)
SQL
Fundamentals
Databases
Similar Kata:
Stats:
Created | Oct 31, 2016 |
Published | Oct 31, 2016 |
Warriors Trained | 18446 |
Total Skips | 2799 |
Total Code Submissions | 43669 |
Total Times Completed | 7545 |
SQL Completions | 7542 |
Total Stars | 254 |
% of votes with a positive feedback rating | 94% of 945 |
Total "Very Satisfied" Votes | 855 |
Total "Somewhat Satisfied" Votes | 74 |
Total "Not Satisfied" Votes | 16 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |