Trouble grabbing values for multiple IDs

  • Trying to get a total of instances of events and assigning it an alias

    (SELECT COUNT(id) from Finish f1 where PerfDate = '2013-04-18' and NoEvent = 'yes' ) AS numbercancelled

    ...but if there are more than one ID that had a NoEvent = 'yes' , i dont want the grand total of both IDs, but individual totals.

    group by here don't work because I just need one value for numbercancelled, I'm wondering if i need an sql function to return a value for each ID, where result would be something like:

    ID numbercancelled

    100 3

    115 7

  • znetznet (4/23/2013)


    Trying to get a total of instances of events and assigning it an alias

    (SELECT COUNT(id) from Finish f1 where PerfDate = '2013-04-18' and NoEvent = 'yes' ) AS numbercancelled

    ...but if there are more than one ID that had a NoEvent = 'yes' , i dont want the grand total of both IDs, but individual totals.

    group by here don't work because I just need one value for numbercancelled, I'm wondering if i need an sql function to return a value for each ID, where result would be something like:

    ID numbercancelled

    100 3

    115 7

    Not having alot to work with this may help:

    select

    st.*,

    nc.numbercancelled.

    from

    dbo.SomeTable st

    cross apply (SELECT COUNT(id) AS numbercancelled from Finish f1 where PerfDate = '2013-04-18' and NoEvent = 'yes' and f1.id = st.id) nc(numbercancelled)

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

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