QueryDsl中的用户定义的SQL变量

时间:2018-10-23 16:05:20

标签: mysql spring-boot spring-data-jpa querydsl

我希望在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变量。

0 个答案:

没有答案