MySQL偏移日期分组依据

时间:2011-07-19 15:11:45

标签: mysql

我有以下查询正在提取数据。它目前按月和年分组数据。我试图将月度数据从一个月的19个分组到下一个的18个月,以便它符合我们的财务月份而不是calander月份。这可能吗?

SELECT
    sum(invoice.invoice_amount_payable)AS invoice_totals,
    company.company_label AS company_label,
    MONTHNAME(invoice.invoice_date_paid)AS MONTH,
    YEAR(invoice.invoice_date_paid)AS YEAR
FROM
    invoice
INNER JOIN company ON invoice.company_id = company.company_id
WHERE
    invoice.invoice_active = 1
AND invoice.invoice_status_id = 7
AND invoice.invoice_date_deleted = 0
AND invoice.invoice_date_paid >= '2009-1-1'
AND invoice.invoice_date_paid <= '2011-8-20'
GROUP BY
    MONTH(invoice.invoice_date_paid),
    YEAR(invoice.invoice_date_paid)
ORDER BY
    YEAR(invoice.invoice_date_paid),
    MONTH(invoice.invoice_date_paid)

1 个答案:

答案 0 :(得分:0)

要使用mysql的月份和年份功能,您只需将发票日转换为所需的偏移量,如:

invoice_date_paid + INTERVAL 19 DAY