querydsl-如何获取列的总和

发布于 2025-02-13 13:24:54 字数 1192 浏览 0 评论 0原文

这些是

id, bigint(20)
available_quantity, int(11)
allocation_quantity, int(11)
stop_quantity, int(11)
damage_quantity, int(11)
standby_quantity, int(11)

我想进行查询的库存表信息,而不是在sql中进行查询:

SELECT 
 available_quantity,
 allocation_quantity,
 stop_quantity,
 damage_quantity,
 standby_quantity,
 available_quantity + allocation_quantity + standby_quantity
FROM STOCK

我尝试搜索解决方案,但是我得到的最接近的是:

     return queryFactory
                .select(new QStockResponseDto(
                        stock.availableQuantity,
                        stock.standbyQuantity,
                        stock.allocationQuantity,
                        stock.availableQuantity + stock.standbyQuantity + stock.allocationQuantity 
                )).from(stock)

但这表示以下错误,

Operator '+' cannot be applied to 'com.querydsl.core.types.dsl.NumberPath<java.lang.Integer>', 'com.querydsl.core.types.dsl.NumberPath<java.lang.Integer>'

我不知道如何获得'obilit_quantity + Alapocation_Quantity + Standby_quantity'在querydsl中:

These below is my STOCK TABLE info

id, bigint(20)
available_quantity, int(11)
allocation_quantity, int(11)
stop_quantity, int(11)
damage_quantity, int(11)
standby_quantity, int(11)

I'd like to do a query than in sql it's:

SELECT 
 available_quantity,
 allocation_quantity,
 stop_quantity,
 damage_quantity,
 standby_quantity,
 available_quantity + allocation_quantity + standby_quantity
FROM STOCK

I tried searching for the solution, but the closest I get was:

     return queryFactory
                .select(new QStockResponseDto(
                        stock.availableQuantity,
                        stock.standbyQuantity,
                        stock.allocationQuantity,
                        stock.availableQuantity + stock.standbyQuantity + stock.allocationQuantity 
                )).from(stock)

but this indicates below error

Operator '+' cannot be applied to 'com.querydsl.core.types.dsl.NumberPath<java.lang.Integer>', 'com.querydsl.core.types.dsl.NumberPath<java.lang.Integer>'

i don't know how to get this 'available_quantity + allocation_quantity + standby_quantity' in QueryDSL:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所有深爱都是秘密 2025-02-20 13:24:54

错误消息为您提供了有关该问题的很好的提示。价值库存。可利用股票,股票。定位和库存。合规量都是numberexpression类型的对象。在此处阅读NumbereXpression文档:

https://querydsl.com/static/querydsl/latest/apidocs/com/com/querydsl/core/core/coore/types/dsl/numberexpression.html

我目前没有Querydsl local设置此时间来验证此时间,但我认为您只需要替换:

stock.availableQuantity + stock.standbyQuantity + stock.allocationQuantity

与此:

stock.availableQuantity.add(stock.standbyQuantity).add(stock.allocationQuantity)

如果您需要为此结果提供别名,请附加。让我们知道这是否有效。

The error message gives you a great hint about the issue. The value stock.availableQuantity, stock.standbyQuantity, and stock.allocationQuantity are all objects of type NumberExpression. Read the NumberExpression documentation here:

https://querydsl.com/static/querydsl/latest/apidocs/com/querydsl/core/types/dsl/NumberExpression.html

I do not have QueryDSL set up local at this time to validate this, but I think you simply need to replace:

stock.availableQuantity + stock.standbyQuantity + stock.allocationQuantity

with this:

stock.availableQuantity.add(stock.standbyQuantity).add(stock.allocationQuantity)

If you need to provide an alias for that result, append the .as(Path<>) method after the second add() method. Let us know if this works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文