Query to sum total time

  • I am having trouble writing a query that will some the total time for an event. I have 2 columns of data, Encounter_Code, Duration. I need the total unique number of Encounter_Code, My code for this part is Count(Encounter_Code) AS Total, and this is working, but when I try and sum the total duration of every event for one Encounter_Code I don't know where to start. Any suggestions?

    Thanks

  • Hey Cagan,

    Welcome to SSC. It would be easier to help you if you check out the first link in my sig, which will walk you through proving some sample structure and data so that we could write code to show you want you want to do, as well as explaining what said code is doing.

    In short, you need two separate statements. One doing the SELECT COUNT ( DISTINCT encounter_number) with no GROUP BY, and another doing a SELECT SUM( DATEDIFF()) FROM tbl GROUP BY Encounter_Number.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

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

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