我希望在mysql
中表达以下QueryDsl
查询:
SELECT AVG(dd.val) as median_val
FROM (
SELECT d.balance as val, @rownum:=@rownum+1 as `row_number`, @total_rows:=@rownum
FROM message_entity d, (SELECT @rownum:=0) r
WHERE d.balance is NOT NULL
-- put some where clause here
ORDER BY d.balance
) as dd
WHERE dd.row_number IN ( FLOOR((@total_rows+1)/2), FLOOR((@total_rows+2)/2) );
此查询用于获取数据库中某些列值的MEDIAN
。挑战在于表达用户定义的sql变量。