Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need to calculate Avg within the select query

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2014-02-25 : 10:05:17
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

6 Posts

Posted - 2014-02-25 : 10:20:15
Have you tried


AVG ( [ ALL | DISTINCT ] expression )


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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-02-25 : 11:30:57
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
   

- Advertisement -