Query to get Last month's data and current month's data

  • Hi Gurus,

    Is there way in SQL query to get the count of certain data that would display the last month's data and current month's data. For example...

    SELECT count(prt_created = lastMonth) as lastMonthData,

    count(prt_created = currentMonth) as currentMonthData

    FROM PARTICIPLES

    Something like above... where I can display their count on the table rows..

    Last Month | This Month

    10 | 11

    12 | 9

  • It's a crosstab:

    SELECT SUM(CASE WHEN prt_created = lastMonth THEN 1 ELSE 0 END) as lastMonthData,

    SUM(CASE WHEN prt_created = currentMonth THEN 1 ELSE 0 END) as currentMonthData

    FROM PARTICIPLES

    Hope this helps

    -- Gianluca Sartori

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply