Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Finding the median in intersystems cache SQL

Question
Abdul-Rashid Yakubu · Mar 22, 2022

Finding the median in intersystems cache SQL

Hi,

Is there a way to find the median in Intersystems Cache SQL? I know it is not available as an aggregate function. Also in SQL Server I could try something like: 

 

SELECT
(
 (SELECT MAX(Score) FROM
   (SELECT TOP 50 PERCENT Score FROM Posts ORDER BY Score) AS BottomHalf)
 +
 (SELECT MIN(Score) FROM
   (SELECT TOP 50 PERCENT Score FROM Posts ORDER BY Score DESC) AS TopHalf)
) / 2 AS Median

However, there is no PERCENT Keyword in Cache as well. Any suggestions?

 

Thanks

#SQL #Caché
Product version: Caché 2012.1

Source URL:https://community.intersystems.com/post/finding-median-intersystems-cache-sql