Median value MYSQL

Hi,
I want to run some statistics on our table, I have Mean and Mode etc but struggling to write a query for the Median and STD Deviation. Has anyone done this before, or have an example they could share?

Thanks,

Andrew

Does this help? You’d need to use the custom query function. For things like this prefer to write/run the code in my database admin GUI (Navicat) and then copy into a custom query in Wappler. Adding in any dynamic parameters as necessary.

Thanks
I now have STD resolved, just struggling with Median.

Thanks Philip,
So have the query in Navicat working, but cant get the following to work at a custom query in Wappler.

SET @rowindex := -1;
 
SELECT
   AVG(d.Velocity) as Median 
FROM
   (SELECT @rowindex:=@rowindex + 1 AS rowindex,
           Sensors.Velocity AS Velocity
    FROM Sensors
    ORDER BY Sensors.Velocity) AS d
WHERE
d.rowindex IN (FLOOR(@rowindex / 2), CEIL(@rowindex / 2));

Sorry… can’t be much more help here, haven’t run through it myself…

Thanks, anyone else know, @Hyperbytes, @Teodor ?