如何通过mysql查询计算中间数

如何通过mysql查询计算中间数,mysql,date,mysql-workbench,median,Mysql,Date,Mysql Workbench,Median,我有一个表order\u match,其中包含order\u buyer\u id作为交易id,createdby作为买方,createdAt作为交易开始日期,quantity作为交易金额,单位为kg 在这种情况下,我想计算每个买家的平均、最小、最大数量,这些买家在一段时间内交易超过一次,我得到了我的平均、最小、最大数量,但我没有得到中间值。 以下是表格示例: CREATE TABLE order_match (`order_buyer_id` int, `createdby`

我有一个表order\u match,其中包含order\u buyer\u id作为交易id,createdby作为买方,createdAt作为交易开始日期,quantity作为交易金额,单位为kg

在这种情况下,我想计算每个买家的平均、最小、最大数量,这些买家在一段时间内交易超过一次,我得到了我的平均、最小、最大数量,但我没有得到中间值。 以下是表格示例:

CREATE TABLE order_match
        (`order_buyer_id` int, `createdby` int, `createdAt` datetime, `quantity` decimal(10,2))
    ;

    INSERT INTO order_match
        (`order_buyer_id`, `createdby`, `createdAt`, `quantity`)
    VALUES
        (19123, 19, '2017-02-02', 5),
        (193241, 19, '2017-02-03', 5),
        (123123, 20, '2017-02-03', 1),
        (32242, 20, '2017-02-04', 4),
        (32434, 20, '2017-02-04', 5),
        (2132131, 12, '2017-02-02', 6)
    ;
这就是我正在研究的语法

 select
           MAX(om.quantity) AS max,
           MIN(om.quantity) AS min,
           SUM(om.quantity)/ x1.count_ AS average
      from (select count(xx.count_) as count_
              from (select count(createdby) as count_ from order_match
                     group by createdby
                     having count(createdby) > 1) xx
            ) x1,
            (select createdby
               from order_match
              group by createdby
              having count(createdby) > 1) yy,
            order_match om
     where yy.createdby = om.createdby
       and om.createdAt <= '2017-02-04'
       and EXISTS (select 1 from order_match om2
                    where om.createdby = om2.createdby
                      and om2.createdAt >= '2017-02-02'
                      and om2.createdAt <= '2017-02-04')
请帮我找出这个案例的中值

这是小提琴


这回答了你的问题吗?先生,你能解释一下吗?也许你的新语法会对我有所帮助,因为我试过你的建议,但还是不能实现。