Please see my other Database Development articles.
Dynamically restructuring report data
Often when creating reports, data is received in varying formats, some of which make it difficult to create a visually compelling format. One example of such data is when the structure itself is embedded within the data.
As you see below, the initial record set begins with a company’s data. The native structure of the data rests within the “dept_type” column with values of accounting, sales, and it.
After executing a simple SELECT statement making use of the PIVOT keyword, the simple structure of the data previously hidden, is now clearly used to provide an overview of the company’s various departments.
Also, I’ve decided to provide a sum of each departments’ salaries.