For some businesses, the data stored in the table and its final grid performance is exactly the equivalent of reversing the source table, so this time we have a problem of how to convert rows into columns, and to simplify the problem, we look at the following query data, you do not have to care about the design of the table and SQL statements:
Suppose the SQL statement used is:
SELECT [姓名],[时代],[金钱]
FROM [test].[dbo].[people]
This table stores the gold coins owned by two people in different eras (times are fixed by three: young, middle-aged and old), of which:
John has 1000, 5000 and 800 gold coins in young, middle-aged and old age respectively;
Dick has 1200, 6000, and 500 gold coins in young, middle-aged and old age respectively.
Now we want to show the coins that two people have at different stages in a form similar to the following:
Name |
Young |
Middle |
Elderly |
Tom |
1000 |
5000 |
800 |
John doe |
1200 |
6000 |
500 |