我有Items类:
@Entity
@Table(name ="Items")
Class Items{
@ID
private long id;
private String upc;
private long itemNo;
private int qty;
-----
}
我需要在QueryDSL的JPAQuery中创建以下sql语句。
select itemNo, upc, count(*) t from Items group by ITEM_NO, UPC order by t;
QueryDSL示例需要针对order by子句进行修改:
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());
需要帮助才能正确起草此查询?
答案 0 :(得分:5)
这应该有效
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));