Need a MYSQL function to calculate a percentile by group
$10-30 USD
ปิดแล้ว
โพสต์ ประมาณ 6 ปีที่ผ่านมา
$10-30 USD
ชำระเงินเมื่อส่งงาน
My data is in columns A-E here
https://docs.google.com/spreadsheets/d/1DTb7-d7TNHZIFqm0m3sgtgS6m0M5DPzUZp1LigltKdM/edit#gid=824377488
Each reviewer (id in column C) assigned a score (column E) to companies (id in column B)
I need to calculate a percentile of that score within each reviewer. E.g. if reviewer X reviewed 4 companies and gave them scores of 1,2,3,4 they will get percentiles of 0, 0.333, 0.666, 1
Further requirements are:
1) I need to be able to upload this function and use it for different datasets in statements like this
select *, MyPercentile(reviewer_id, score) from rating
2) NULL scores should return NULL percentiles
3) Those NULLs should also be completely ignored in a group, i.e. imagine there are fewer values there
4) In column F of the spreadsheet, I provided the Excel calculation of those percentiles. However, I do not like how Excel handles ties. I want the percentiles for tied values to be based on the average, not on minimum, i.e.
--- If all values in the group are identical, everybody gets a percentile of 0.5 (not 0, as in Excel)
--- If in a large group half of the values = 1 and other half = 2, then the first half gets the percentile of 0.25 and the second gets 0.75
I provided the desired values for the first two reviewers in the MyPercentile column.
I also attached the screenshot with the version of MySQL and phpmyadmin.
Please say something meaningful in your proposal, not just the generic "I am an expert and I can do it" stuff.