Below is an example of calculating quartiles for ranges of e256 values ββwithin e32 groups, the index in (e32, e256) in this case is mandatory:
SELECT @group:=IF( e32=@group , e32, GREATEST(@index:=-1, e32)) as e32_, MIN(e256) as so, MAX(IF(lq_i=(@index: =@index +1), e256, NULL)) as lq, MAX(IF( me_i=@index , e256, NULL)) as me, MAX(IF( uq_i=@index , e256, NULL)) as uq, MAX(e256) as lo FROM (SELECT @index:=NULL, @group:=NULL) as init, test t JOIN ( SELECT e32, COUNT(*) as cnt, (COUNT(*) div 4) as lq_i,
If no groups are needed, the query will be a little easier.
PS test is my random value playground table, where e32 is the result of Python int(random.expovariate(1.0) * 32) , etc.
source share