querydsl-如何获取列的总和
这些是
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息为您提供了有关该问题的很好的提示。价值库存。可利用股票,股票。定位和库存。合规量都是numberexpression类型的对象。在此处阅读NumbereXpression文档:
https://querydsl.com/static/querydsl/latest/apidocs/com/com/querydsl/core/core/coore/types/dsl/numberexpression.html
我目前没有Querydsl local设置此时间来验证此时间,但我认为您只需要替换:
与此:
如果您需要为此结果提供别名,请附加。让我们知道这是否有效。
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:
with this:
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.