实例1:

SET @ID = 0;
SELECT
AVG(loan_amount)
from
(
SELECT @ID:=@ID+1 as ID, loan_amount
FROM   table_xxx ORDER BY loan_amount
) a where IF( ROUND(@ID/2,0)%2=0,ID in (ROUND(@ID/2,0),ROUND(@ID/2,0)/2 + 1), ID=ROUND(@ID/2,0) )

 

 

 

实例2:

SET @ID = 0;
SELECT
AVG(totallimit)
from
(
SELECT @ID:=@ID+1 as ID,t.*
FROM
(
SELECT pp.capitalid, pp.totallimit
FROM table1 pp
INNER JOIN table2 ppc ON pp.capitalid = ppc.capitalid
WHERE
pp.isduifu = 0
and pp.inserttimestamp <='2019-05-31 23:59:59'
and ppc.faxingjigou like '%R360%'
ORDER BY pp.totallimit
) t
) a where IF( ROUND(@ID/2,0)%2=0,ID in (ROUND(@ID/2,0),ROUND(@ID/2,0) + 1), ID=ROUND(@ID/2,0) );

posted on 2019-06-12 11:37  毛会懂  阅读(240)  评论(0编辑  收藏  举报