如何复制联接的所有值,以便查询的联接的每个值?

时间:2018-07-06 16:29:04

标签: mysql join

我很麻烦。 我已经写了这个查询:

select a.Date, SUM(pl.ore) as ore, pl.fk_dipendente from (
    select last_day("2018-07-01") - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
    from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
    cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
    cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c ) a
left join (select * from ttr_posizioni_lavorate) pl ON (pl.data = a.Date) where a.Date between "2018-07-01" and last_day("2018-07-01") group by a.Date, pl.fk_dipendente order by a.Date

这是数组的结果

Array
(

[60012144] => Array
    (
        [2018-07-04] => 9
        [2018-07-06] => 9
    )

[60241876] => Array
    (
        [2018-07-04] => 9
        [2018-07-05] => 9
        [2018-07-06] => 9
    )

)

我想查看每个月的foreach子数组,其值为0。例如:

[60012144] => Array
    (
        [2018-07-01] => 0
        [2018-07-02] => 0
        [2018-07-03] => 0
        [2018-07-04] => 9
        [2018-07-05] => 0
        [2018-07-06] => 9
        [2018-07-07] => 0
        [2018-07-08] => 0
        [2018-07-09] => 0
        [2018-07-10] => 0
        ...
    )
[60241876] => Array
    (
        [2018-07-01] => 0
        [2018-07-02] => 0
        [2018-07-03] => 0
        [2018-07-04] => 9
        [2018-07-05] => 9
        [2018-07-06] => 9
        [2018-07-07] => 0
        [2018-07-08] => 0
        [2018-07-09] => 0
        [2018-07-10] => 0
        ...
    )

实际上,不具有联接的查询将返回该月内的所有日期,而具有联接的查询仅返回对应于联接的日期。我该怎么做? 非常感谢

0 个答案:

没有答案