假设我有以下数据集
+--------------+-----------------------------+------------+-----+-----------+-----------+
| account_name | PositionDescription | FullDate | Day | DayName | ShiftType |
+--------------+-----------------------------+------------+-----+-----------+-----------+
| employee1 | Customer Support Specialist | 2012-11-01 | 1 | Thursday | G |
| employee1 | Customer Support Specialist | 2012-11-03 | 3 | Saturday | G |
| employee1 | Customer Support Specialist | 2012-11-05 | 5 | Monday | G |
| employee1 | Customer Support Specialist | 2012-11-06 | 6 | Tuesday | G |
| employee1 | Customer Support Specialist | 2012-11-08 | 8 | Thursday | G |
| employee1 | Customer Support Specialist | 2012-11-10 | 10 | Saturday | G |
| employee1 | Customer Support Specialist | 2012-11-12 | 12 | Monday | G |
| employee1 | Customer Support Specialist | 2012-11-13 | 13 | Tuesday | G |
| employee1 | Customer Support Specialist | 2012-11-15 | 15 | Thursday | G |
| employee1 | Customer Support Specialist | 2012-11-17 | 17 | Saturday | G |
| employee1 | Customer Support Specialist | 2012-11-19 | 19 | Monday | G |
| employee1 | Customer Support Specialist | 2012-11-20 | 20 | Tuesday | G |
| employee1 | Customer Support Specialist | 2012-11-22 | 22 | Thursday | G |
| employee1 | Customer Support Specialist | 2012-11-24 | 24 | Saturday | G |
| employee1 | Customer Support Specialist | 2012-11-26 | 26 | Monday | G |
| employee1 | Customer Support Specialist | 2012-11-27 | 27 | Tuesday | G |
| employee1 | Customer Support Specialist | 2012-11-29 | 29 | Thursday | G |
| employee2 | Game Support Specialist | 2012-11-02 | 2 | Friday | M |
| employee2 | Game Support Specialist | 2012-11-03 | 3 | Saturday | M |
| employee2 | Game Support Specialist | 2012-11-04 | 4 | Sunday | M |
| employee2 | Game Support Specialist | 2012-11-07 | 7 | Wednesday | M |
| employee2 | Game Support Specialist | 2012-11-09 | 9 | Friday | M |
| employee2 | Game Support Specialist | 2012-11-10 | 10 | Saturday | M |
| employee2 | Game Support Specialist | 2012-11-11 | 11 | Sunday | M |
| employee2 | Game Support Specialist | 2012-11-14 | 14 | Wednesday | M |
| employee2 | Game Support Specialist | 2012-11-16 | 16 | Friday | M |
| employee2 | Game Support Specialist | 2012-11-17 | 17 | Saturday | M |
| employee2 | Game Support Specialist | 2012-11-18 | 18 | Sunday | M |
| employee2 | Game Support Specialist | 2012-11-21 | 21 | Wednesday | M |
| employee2 | Game Support Specialist | 2012-11-23 | 23 | Friday | M |
| employee2 | Game Support Specialist | 2012-11-24 | 24 | Saturday | M |
| employee2 | Game Support Specialist | 2012-11-25 | 25 | Sunday | M |
| employee2 | Game Support Specialist | 2012-11-28 | 28 | Wednesday | M |
| employee2 | Game Support Specialist | 2012-11-30 | 30 | Friday | M |
+--------------+-----------------------------+------------+-----+-----------+-----------+
是否可以将其格式化为这张表?
+--------------+-----------------------------+----------------+ | account_name | PositionDescription | 1 | 2 | 3 | 4 | and so on... +--------------+-----------------------------+------------+---+ | employee1 | Customer Support Specialist | G | G | G | G | | employee2 | Game Support Specialist | G | G | G | G | +-----------------------------+------------+-----+------------+
我试图使用 PIVOT 来解决这个问题,但我无法理解。我不知道这是否可能:(
假设这是原始查询
SELECT account_name
,PositionDescription ,FullDate, Day, DayName ,ShiftType
FROM ManpowerSchedule ms