SQL – Sort into groups, then sort within groups

I recently came across a complex sorting problem that required sorting the data into groups, then further sorting the data within each group. I’ll explain this problem with a concrete example, and then I’ll show the SQL query I used to solve the problem. Let’s say we have orders, departments, and users. Users can be … Read more