A walkthrough of a medium-difficulty SQL interview problem: generating a salary report from three input tables (salary, income, deduction). The solution covers populating an employee transaction table using CROSS JOIN and UNION, then transforming row-level data into columnar format. Two approaches are demonstrated: PostgreSQL's crosstab function (via the tablefunc extension) and Microsoft SQL Server's PIVOT operator. Key concepts include integer division pitfalls, the importance of ORDER BY in crosstab queries, and computing derived columns like gross salary, total deductions, and net pay.
•30m watch time
1 Impression