【问题标题】:How to transpose dynamic matrix dataset in EXCEL or SQL如何在 EXCEL 或 SQL 中转置动态矩阵数据集
【发布时间】:2015-09-04 08:31:53
【问题描述】:

我有以下问题,我找不到最佳解决方案。

我需要将工作表中每个 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)

【问题讨论】:

    标签: mysql sql excel transpose vba


    【解决方案1】:

    这在 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
    

    然后根据需要进行排序。

    编辑:如果您需要有关日期的帮助,请告诉我们。

    【讨论】:

    • 非常感谢米海。我会调查一下并告诉你。
    猜你喜欢
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 2017-04-23
    • 2015-06-11
    • 2021-09-01
    • 1970-01-01
    • 2013-03-07
    相关资源
    最近更新 更多