Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Median Calculation on T-SQL need Help

$
0
0

Hi Team,

Thanks for looking into my question.

I need a T-SQL logic for Median calculation as derived column .

--Table Creation :

create table EMP_MEDIAN ( Statusid int ,Statusname varchar(20),DepartmentName varchar(20),EMPID int,Daysinstatus int)

--Inserting records

insert into EMP_MEDIAN values (1,'Active','DW',100,806),(1,'Active','DW',102,695),(1,'Active','DW',103,695),(2,'InActive','SAP',104,100),
(2,'InActive','SAP',105,200),(2,'InActive','SAP',106,300),(2,'InActive','SAP',107,400)

--View the data

select * from emp_median

After executing the above query i would require a result as Expeted O/P Median  as separate column as below sheet. 

Status IDStatus nameDepartmentEmpIDnoofDaysExpected O/P Median
1ActiveDW100806695
1ActiveDW101695695
1ActiveDW102695695
2InactiveSAP103100250
2InactiveSAP104200250
2InactiveSAP105300250
2InactiveSAP106400250

If  i pass the EMPID =100  then my median values 695 or empid 105 median value is 250.

Could you help us the logic to achieve the results.

Thanks in advance and really appreciate for help.

Regards,

Suneel


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>