SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need to calculate Avg within the select query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

541 Posts

Posted - 02/25/2014 :  10:05:17  Show Profile  Reply with Quote
I need to calculate the Average, from table encounter
i have the below three columns, how i can put the logic within the select query

sum(disch_date - admit_date)/ count(distinct encounter_id)

Thank you very much for the helpful info.

RonnieRahman
Starting Member

United Kingdom
6 Posts

Posted - 02/25/2014 :  10:20:15  Show Profile  Reply with Quote
Have you tried


AVG ( [ ALL | DISTINCT ] expression ) 


Here is the link: http://technet.microsoft.com/en-us/library/ms177677 v=sql.105 .aspx
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 02/25/2014 :  11:30:57  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SUM(DATEDIFF(DAY, Admit_Date, Disch_Date)) / COUNT(DISTINCT Encounter_ID)



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000