Reputation: 31
I have Items class:
@Entity
@Table(name ="Items")
Class Items{
@ID
private long id;
private String upc;
private long itemNo;
private int qty;
-----
}
I need to make below sql statement from JPAQuery of QueryDSL.
select itemNo, upc, count(*) t from Items group by ITEM_NO, UPC order by t;
QueryDSL sample needs modification for order by clause:
QItems items = QItems.items;
query.from(items)
.groupBy(items.itemNo,items.upc)
.orderby(<Dont Know How to sort on count>).list(items.itemNo,items.upc,items.count());
Need help to draft this query properly?
Upvotes: 2
Views: 2817
Reputation: 22180
This should work
NumberPath<Long> count = Expressions.numberPath(Long.class, "c");
QItems items = QItems.items;
query.from(items)
.groupBy(items.itemNo,items.upc)
.orderby(count.asc())
.list(items.itemNo,items.upc,items.count().as(count));
Upvotes: 7