Oracle SQL-查找表中最大匹配日期的行的计数
我正在尝试使用查询来从行返回计数,以使行的日期与表中该列的最大日期匹配。
Oracle SQL:版本11.2:
以下语法似乎是正确的(对我而言),并且编译和运行。但是,它不仅返回最大计数,而是像“ haivng”子句一样返回几个计数。
Select ourDate, Count(1) as OUR_COUNT
from schema1.table1
group by ourDate
HAVING ourDate = max(ourDate) ;
请问如何解决?
I am trying to use a query to return the count from rows such that the date of the rows matches the maximum date for that column in the table.
Oracle SQL: version 11.2:
The following syntax would seem to be correct (to me), and it compiles and runs. However, instead of returning JUST the count for the maximum, it returns several counts more or less like the "HAIVNG" clause wasn't there.
Select ourDate, Count(1) as OUR_COUNT
from schema1.table1
group by ourDate
HAVING ourDate = max(ourDate) ;
How can this be fixed, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用:
OR:
对于示例数据:
两者都输出:
db< “>在这里
You can use:
or:
Which, for the sample data:
Both output:
db<>fiddle here
我不知道我是否了解您想要什么。尝试以下操作:
I don't know if I understand what you want. Try this:
一种选项是使用获取最大日期的子查询:
或者,更多 Modern 方法(如果您的数据库版本支持它;虽然11G不支持它):
One option is to use a subquery which fetches maximum date:
Or, a more modern approach (if your database version supports it; 11g doesn't, though):