News for hackers. Stuff that matters.
Re:PostgreSQL's Missing DateDiff Function by function_seven on Tuesday December 21, 2021 @09:09PM (#29644778)
If I want a table of figures for the past 18 months, I could aggregate them like so:

    GROUP BY DATEDIFF('month', "transaction_date", NOW())
And get a result set that shows the relative month in one column, and the sum in another.

And those values relative values won't change every month like they would if I just grouped by

    EXTRACT('year-month', "transaction_date") 
(or whatever the syntax is for that)

Also useful for a stored procedure or view than can then be JOINed in other queries as time goes on.

Re:PostgreSQL's Missing DateDiff Function by ants_a on Wednesday December 22, 2021 @09:08AM (#29649454)
In PostgreSQL you would group by date_trunc('month', transaction_date)
Re:PostgreSQL's Missing DateDiff Function by function_seven on Wednesday December 22, 2021 @12:34PM (#29652472)
That would produce dates instead of integers though. I want a table that looks like this:

    MonthsAgo | Sales
    ==================
            4 | 4,500
            3 | 7,204
            2 | 12,578
            1 | 15,748
            0 | 34,485
And maybe use a parameter so the user can go by week, or quarter, or whatever.