2017-09-12 5 views
0

개체 목록을 반환하는 쿼리가 있습니다 (예 : Employee). 그 결과와 함께 무 처리 된 count(*)의 전체를 추가하고 싶습니다. 내가 좋아하는 쿼리를 모방에서 얻을 것이다Querydsl - 두 개 이상의 개체로 결과를 분할합니다.

+---+-------------------+-------------+------------+ 
| |  id   |  age | total | 
+---+-------------------+-------------+------------+ 
| 1 | 1234    | 24   |12   | 
| 2 | 154367   | 61   |12   | 
| 3 | 9485048386  | 36   |12   | 
+---+-------------------+-------------+------------+ 

: 같은 뭔가

나는이 타입의 데이터의 조회 및 List<Employee>total에 대한 단수 Long를 검색 할 수있는 방법
SELECT * , COUNT(*) OVER() AS total 
FROM employee 
LIMIT 3 
OFFSET 0 

? 현재,이가는이 있지만 나는 새로운 total 열/값을 확장하는 방법을 확실 해요 :

projection = Projections.constructor(Employee.class, qEmployee.id, qEmployee.age); 
select(projection).from(qEmployee).where(foobar).offset(0).limit(3); 

답변

0

은 내가 select(...)에 윈도우 함수에 필요한 SQLExpression을 추가하여이를 달성 할 수 있었다. 쿼리는 이제 튜플의 첫 번째 요소는 내 Employee 객체 인 List<Tuple>를 반환하고, 두 번째는 total입니다 :

projection = Projections.constructor(Employee.class, qEmployee.id, qEmployee.age); 
List<Tuple> results = select(projection, SQLExpressions.count().over()).from(qEmployee).where(foobar).offset(0).limit(3);