我有这样的代码:
SELECT `pelamarmagisterrangkuman`.`major` AS `ProgramStudi`,
count(IPKS1) as N,
AVG(IPKS1) as Mean,
MIN(IPKS1) as Minimum,
MAX(IPKS1) as Maximum,
StdDev(IPKS1) as StDev,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(
GROUP_CONCAT(IPKS1 ORDER BY IPKS1 SEPARATOR ','),
',', 50/100 * COUNT(*) + 1), ',', -1) AS decimal) AS `Median`,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(
GROUP_CONCAT(IPKS1 ORDER BY IPKS1 SEPARATOR ','),
',', 25/100 * COUNT(*) + 1), ',', -1) AS decimal) AS `Q1`,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(
GROUP_CONCAT(IPKS1 ORDER BY IPKS1 SEPARATOR ','),
',', 75/100 * COUNT(*) + 1), ',', -1) AS decimal) AS `Q3`
FROM `pelamarmagisterrangkuman` where `pelamarmagisterrangkuman`.`IPKS1` != 0 and `pelamarmagisterrangkuman`.`TahunDaftar` = 2012 group by `pelamarmagisterrangkuman`.`major`
COUNT,AVG,MIN,MAX和MIN可以正常工作。但是,四分位数不能正常工作。我的意思是,上面代码的结果是整数值。但是,我期望的结果不仅是整数值,而且还有浮点值,因为我的数据在浮点和整数值中。我该怎么做才能解决此问题?提前致谢
最佳答案
在算术中避免整数例如
50.0 / 100.0 *强制转换(COUNT(*)为十进制)+ 1.0
关于mysql - SQL中的四分位数查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44992259/