Hi All I am new to SQL and I need to calculate the Average length of stay for a list of patients, the table looks like the below, the total number of patient is 1300
Table1
Patient ID...........Admission date...........Discharge date
p123.................. 2015-01-01................2015-01-03
p154.................. 2014-02-03................2014-02-12
P144................. 2015-03-06............... 2015-05-09
please always provide sample data in the following form
create table #notgood(patientid varchar(50), admissiondate date, dischargeDate date)
insert into #notgood
select 'p123', '2015-01-01', '2015-01-03' union
select 'p154','2014-02-03', '2014-02-12' union
select 'P144', '2015-03-06', '2015-05-09'
select avg(datediff(d, admissiondate, dischargeDate))
from #notgood
drop table #notgood
Hi Thanks for the reply, sorry as I am new to this but the table looks like this:
The number of patient are huge, more than 1300, I hope I do not need to do each patient separately as shown in your SQL.
we do not yet have a technology that extracts/scraps data from an image attachment so you are going to have to provide the sample data as recommended. otherwise it will be hard to provide you assistance. in other words I ain't got time to type it all for you, you will need to do it for us.
select avg(datediff(d, admissiondate, dischargeDate))
from your patientTable
that was just an example
Hi
There are OnLine WebSites that extract data from images
Please check them OUT
Thanks
sarcasm
JUST trying to be NICE
Thank you for trying being nice.
- Calculate the length of stay for each row:
SELECT LengthOfStay = DATEDIFF(day, AdmissionDate, DischargeDate) FROM Patients
- Get the average:
SELECT AvgLengthOfStay = AVG(DATEDIFF(day, AdmissionDate, DischargeDate)) FROM Patients