Help- Count by Month

  • Hi,

    I have this statment group by

    SELECT wh_id as Wh, count(*) as Plan FROM Backtest where wh_id in (1,9) group by wh_id

    In a table i have the field create_dtim in this format 07-11-2015 10:58:38.

    Ho i can have the result by month because i need a count for every records by month?

    Thks a lot for help,

    Regards,

    JC

  • I haven't tested this, but something like this should do the trick.

    SELECT wh_id as Wh, dateadd(m,datediff(m,0,create_dtim),0),count(*) as Plan FROM Backtest where wh_id in (1,9) group by wh_id, datediff(m,0,create_dtim)

  • Hummm,

    Donยดt work ask me for parameter m and wh.

    ๐Ÿ™

    JC

  • Assuming create_dtim is a valid date field

    SELECT wh_id as Wh,

    MONTH(create_dtim) as MonthCreated,

    YEAR(create_dtim) as YearCreated,

    count(*) as Plan

    FROM Backtest

    where wh_id in (1,9)

    group by wh_id, MONTH(create_dtim), YEAR(create_dtim)

    Is that what you're after?

  • Thks a lot.

    Work ๐Ÿ™‚

    Best regards,

    JC

Viewing 5 posts - 1 through 4 (of 4 total)

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