我遇到以下问题,但找不到最佳解决方案。
我需要将工作表中每个 ID 每个日期的小时数与这些参数对齐。我尝试在 Excel 中转置,但只是得到了一个简单的结果,该结果不会给出每个 ID 和日期的行。
工时工作表
年份 = 2015
ID | MON | TUES | WED | THU | FRI | SAT | SUN | WEEKNR
15 | 6 | 8 | 9 | - | - | - | - | 14
16 | - | - | 2 | - | 3 | - | - | 14
17 | - | 3 | 5 | - | - | 5 | - | 14
18 | 9 | - | - | 3 | - | - | - | 14
我希望将 ID 转置为具有如下值(小时)的日期
ID | DATE | HOURS
15 | 30-3-2015 | 6
15 | 31-3-2015 | 8
15 | 1-4-2015 | 9
16 | 1-4-2015 | 2
16 | 3-4-2015 | 3
17 | 31-3-2015 | 3
17 | 1-4-2015 | 5
17 | 4-4-2015 | 5
18 | 30-3-2015 | 9
18 | 2-4-2015 | 3
非常感谢任何建议/解决方案。 SQL或Excel公式(VBA)
最佳答案
这在 sql-server 中很容易(使用表函数)。然而,在 MySQL 中,我能想到的最简单的方法是:
select id, date (use date_ADD() to deduce this), mon as hours from table
union all
select id, date (use date_ADD() to deduce this), tues as hours from table
union all
select id, date (use date_ADD() to deduce this), wed as hours from table
union all
select id, date (use date_ADD() to deduce this), thu as hours from table
union all
select id, date (use date_ADD() to deduce this), fri as hours from table
union all
select id, date (use date_ADD() to deduce this), sat as hours from table
union all
select id, date (use date_ADD() to deduce this), sun as hours from table
然后根据需要进行排序。
编辑:如果您需要有关日期的帮助,请告诉我们。
关于mysql - 如何在EXCEL或SQL中转置动态矩阵数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32393546/