SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query to sum total time


Query to sum total time

Author
Message
cagan
cagan
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 34
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
Evil Kraig F
Evil Kraig F
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20289 Visits: 7660
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 | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search