gpt4 book ai didi

jpa-2.0 - Mysema QueryDSL JPAQuery for SQL groupby 子句和 order by

转载 作者:行者123 更新时间:2023-12-02 10:09:10 26 4
gpt4 key购买 nike

我有 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());

需要帮助来正确起草此查询吗?

最佳答案

这应该有效

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));

关于jpa-2.0 - Mysema QueryDSL JPAQuery for SQL groupby 子句和 order by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21112631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com