使用 Read() 记录计数
我试图弄清楚如何在填充列表视图网格之前获取最大记录数。我正在使用 Oracle 10g DB,并且我已经尝试过:
SELECT COUNT(*) as countNum, status, date, theTitle, theMessage, date2 " & _
"FROM blah blah...
messagebox.show(dr(0))
但这会使 SQL 查询崩溃。似乎我不会在查询中添加与“计数”相关的任何内容,否则它会崩溃,所以除了这之外,我还有其他方法可以查看它返回的记录数吗?
谢谢! :o)
大卫
I am trying to figure out how to get the max record count before i populate a listview grid. I'm using the Oracle 10g DB and I've tried:
SELECT COUNT(*) as countNum, status, date, theTitle, theMessage, date2 " & _
"FROM blah blah...
messagebox.show(dr(0))
But that makes the SQL query crash. It doesnt seem as though i am about to put anything related to "count" in my query or it will crash so is there any other way i can see how many records it returns other than that?
Thanks! :o)
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像这样使用分析计数:
SELECT COUNT(*) over () as countNum, status, date, theTitle, theMessage, date2 " & _
“从巴拉巴拉
Use analytical count like so:
SELECT COUNT(*) over () as countNum, status, date, theTitle, theMessage, date2 " & _
"FROM blah blah
当使用诸如
count
之类的聚合函数时,您需要使用group by
子句适用于结果集中所有非聚合函数结果的字段。When using an aggregate function such as
count
you need to use agroup by
clause for all those fields in your result set that are not the result of an aggregate function.我在WITH子句中的一种动态视图中编写了一次查询,并在一个选择中结合计数并选择该查询。
I wrote your query once in a kind of dynamic view in the WITH clause
and combine a count and select over this query in one select.
我将使用它来检索简单的记录计数。不确定为什么您想要在此操作中提取任何其他字段。如果有选择条件,请应用 WHERE 或 HAVING 子句(根据需要):
然后在代码中使用 cmd.ExecuteScalar 来检索结果。 。 。
I would use THIS to retrieve a simple count of records. Not sure why you would want to pull any other fields in this operation. If there are selection criteria, apply a WHERE or HAVING clause (as appropriate):
THen in your code use cmd.ExecuteScalar to retrieve the result . . .