誰かが私に教えてくれますか、会計年度内に金額を表示する方法を理解できますか?私が使用している会計年度は11月から10月です。ですから、2016年の会計年度は2015年11月から2016年10月までです。MySQL - 会計年度内に毎月の金額の合計を取得する
私の問題は、選択した年の月間の金額のみを表示できることです。どうすればmysqlでこれを行うことができますか?
これは、私が試してみましたクエリですが、それは一年以内にのみ機能します。
select a.account, a.region, sum(n.amount) as 'Total Net',
sum(case when n.savings_date between date_format(n.savings_date, '%Y-11-01') and last_day(date_format(savings_date, '%Y-11-01')) then n.amount end) as `Nov`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-12-01') and last_day(date_format(savings_date, '%Y-12-01')) then n.amount end) as `Dec`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-01-01') and last_day(date_format(savings_date, '%Y-01-01')) then n.amount end) as `Jan`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-02-01') and last_day(date_format(savings_date, '%Y-02-01')) then n.amount end) as `Feb`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-03-01') and last_day(date_format(savings_date, '%Y-03-01')) then n.amount end) as `Mar`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-04-01') and last_day(date_format(savings_date, '%Y-04-01')) then n.amount end) as `Apr`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-05-01') and last_day(date_format(savings_date, '%Y-05-01')) then n.amount end) as `May`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-06-01') and last_day(date_format(savings_date, '%Y-06-01')) then n.amount end) as `Jun`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-07-01') and last_day(date_format(savings_date, '%Y-07-01')) then n.amount end) as `Jul`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-08-01') and last_day(date_format(savings_date, '%Y-08-01')) then n.amount end) as `Aug`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-09-01') and last_day(date_format(savings_date, '%Y-09-01')) then n.amount end) as `Sep`,
sum(case when n.savings_date between date_format(n.savings_date, '%Y-10-01') and last_day(date_format(savings_date, '%Y-10-01')) then n.amount end) as `Oct`
from
net_savings n left join accounts a
on a.id = n.account_id
where year(n.savings_date) = '2016'
group by a.account
order by a.account desc
私はまた、このような出力を必要としています:
は、あなたの答えや提案に感謝! :)
を試してみてください - それは我々がアプリケーションレベルまたはプレゼンテーションleyerでそれを行うことはできません – Strawberry
利用可能だと仮定します。 – Dhenn
その場合はhttp://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simpleを参照してください。 -sql-query – Strawberry