课程: SQL Practice: Window Functions
Solution: Summarize weekly pay by department
- [Instructor] This challenge asked us to return the total of the weekly pay values for each department as we return rows in the table. To solve this, I started out with the fields that the challenge asks for and then I used a sum function for the weekly pay values and set my window to partition by department. So when summing up the weekly pay values, the database keeps that activity constrained to records that have the same department value. Records with different department values are treated separately and have their own sum. So for each record with a department field of hospitality, for example, we get the sum of the weekly pay for all the records in that department in our new field, and records in the marketing department will have a separate total. I named this field DeptTotal as the challenge requests, and I'm sorting the results first by department and then by weekly pay. I'll run this, and let's see if my result matches the expected output. It does. Great. We've solved the challenge.