Help required on counting functions in SQL

  • Hi all,

    I have a table containing problem ticket information for our company.

    I want to create a view that is snapshotted on a monthly basis, which counts the total number of rows with a created date of the current month, the total number of rows containing a created date withint the current month, and a count of the total created minus the total closed (for the whole table, not just he current month)

    I can do the counts for the whole table, buit i'm not sure how I can have a count based on a criteria with a count on all records in the same bit of SQL..

    help please.

    thanks in advance,

    Matt

  • Use a "conditional count" to do that. Looks something like this (one of several methods - but this is the one I use)

    select count(*) as TotalCount,

    sum(case when MySubCriteria=1 --<--replace this with criteria holding true for what you want

    then 1

    else 0 end) as Subcount

    from mytable

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • ah, of course!

    thank you very much.

    Matt

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

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