Zliczanie rekordów każdego dnia od najstarszej daty w tabeli

0

Cześć wszystkim, poszukuję rozwiązania na zbudowanie, zapytania w sql, które zliczało by ilość rekordów każdego dnia, zaczynając od najstarszej daty w tabeli, o ile.
Tak, tak... SELECT count(*), de from table group by de. Wszystko fajnie, ale ja potrzebuję zapytania, które będzie brało każdy możliwy dzień i pokazywało nawet te dni w których nic nie było.

Jedyne co udało mi się zbudować, to pod dany miesiąc z ostatniego roku.

SELECT
    t1.md as month,
        coalesce(SUM(t1.amount+t2.amount), 0) AS total
    from
    (
        select DATE_FORMAT(a.Date,'%b') as month,
        DATE_FORMAT(a.Date, '%m-%Y') as md,
        '0' as  amount
    from (
        select curdate() - 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
    where a.Date <= NOW() and a.Date >= Date_add(Now(),interval - 12 month)
    group by md
)t1
    left join
    (
        SELECT DATE_FORMAT(de, '%b') AS month, COUNT(id) as amount ,DATE_FORMAT(de, '%m-%Y') as md
    FROM accounts
    where de <= NOW() and de >= Date_add(Now(),interval - 12 month)
    GROUP BY md
)t2
    on t2.md = t1.md
    group by t1.md
    order by t1.md

1 użytkowników online, w tym zalogowanych: 0, gości: 1