Ответы пользователя по тегу MySQL
  • Месяцы в столбцах при group by запросе в MySQL

    @Mulder_ua
    Держи,

    select source,
    sum(case when datepart(mm, date) = 1 then amount else 0 end) as [Январь],
    sum(case when datepart(mm, date) = 2 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 3 then amount else 0 end) aa [...],
    sum(case when datepart(mm, date) = 4 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 5 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 6 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 7 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 8 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 9 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 10 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 11 then amount else 0 end) as [...],
    sum(case when datepart(mm, date) = 12 then amount else 0 end) as [Декабрь]
    group by source

    Буду вопросы, задавай
    Ответ написан
    2 комментария