如何在java spring boot中使用count和row_number
我想使用Cast和Count函数从数据库中获取JPA Spring引导中的数据,但是我的数据没有返回任何ID。因此,我创建了新的字段,该字段使用row_number()
在SQL中返回自动号码。
我在JPA Spring Boot中遇到问题以使用Row_number获取数据,
这是我的SQL语法,
select row_number () over() as id,
cast (t.create_datetime as date) as reportDate,
count(*) as totalTransaction
from vx_transaction."transaction" t
group by cast(t.create_datetime as date)
数据库中的结果如预期
但是,我在JPA Spring中遇到了错误
错误:“ T.ID”列必须通过子句出现在组中或用于 聚合功能
,我正在尝试通过在组中添加ID来解决问题。 代码
select row_number () over() as id,
cast (t.create_datetime as date) as reportDate,
count(*) as totalTransaction
from vx_transaction."transaction" t
group by cast(t.create_datetime as date), id
这是没有错误的
,但是.....结果不如预期不符合预期的结果< /a>
任何人可以帮助我解决这个问题吗?
I want to fetch the data in JPA Spring Boot from database using cast and count function, but my data is not returning any ID. So, I creating new field that returning auto number using row_number()
in SQL.
I'm getting a problem in JPA Spring Boot to fetch the data using row_number,
here is my SQL Syntax
select row_number () over() as id,
cast (t.create_datetime as date) as reportDate,
count(*) as totalTransaction
from vx_transaction."transaction" t
group by cast(t.create_datetime as date)
the result in databases is as expected
but, I'm getting error in JPA Spring
ERROR: column "t.id" must appear in the GROUP BY clause or be used in
an aggregate function
Then, I'm trying to fix the problem with adding the id in group by. Here's the code
select row_number () over() as id,
cast (t.create_datetime as date) as reportDate,
count(*) as totalTransaction
from vx_transaction."transaction" t
group by cast(t.create_datetime as date), id
There is not error, but..... the result not as expected
Can anyone help me to solve this problem??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论