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 ID | Status name | Department | EmpID | noofDays | Expected O/P Median |
1 | Active | DW | 100 | 806 | 695 |
1 | Active | DW | 101 | 695 | 695 |
1 | Active | DW | 102 | 695 | 695 |
2 | Inactive | SAP | 103 | 100 | 250 |
2 | Inactive | SAP | 104 | 200 | 250 |
2 | Inactive | SAP | 105 | 300 | 250 |
2 | Inactive | SAP | 106 | 400 | 250 |
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