使用 Read() 记录计数

发布于 2024-10-14 18:45:24 字数 329 浏览 4 评论 0原文

我试图弄清楚如何在填充列表视图网格之前获取最大记录数。我正在使用 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 技术交流群。

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

发布评论

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

评论(4

迷爱 2024-10-21 18:45:24

像这样使用分析计数:
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

你列表最软的妹 2024-10-21 18:45:24

当使用诸如 count 之类的聚合函数时,您需要使用 group by 子句适用于结果集中所有非聚合函数结果的字段。

When using an aggregate function such as count you need to use a group by clause for all those fields in your result set that are not the result of an aggregate function.

百善笑为先 2024-10-21 18:45:24

我在WITH子句中的一种动态视图中编写了一次查询,并在一个选择中结合计数并选择该查询。

WITH query AS (
 SELECT *
 FROM foobar
 WHERE foo = 1
)
SELECT
  ( SELECT COUNT(*) FROM query ) cnt,
  status,
  date,
  theTitle,
  theMessage
FROM query

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.

WITH query AS (
 SELECT *
 FROM foobar
 WHERE foo = 1
)
SELECT
  ( SELECT COUNT(*) FROM query ) cnt,
  status,
  date,
  theTitle,
  theMessage
FROM query
江湖彼岸 2024-10-21 18:45:24

我将使用它来检索简单的记录计数。不确定为什么您想要在此操作中提取任何其他字段。如果有选择条件,请应用 WHERE 或 HAVING 子句(根据需要):

SELECT COUNT(YourPrimaryKey) As RecordCount
FROM YourTable
GROUP BY YourPrimaryKey

然后在代码中使用 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):

SELECT COUNT(YourPrimaryKey) As RecordCount
FROM YourTable
GROUP BY YourPrimaryKey

THen in your code use cmd.ExecuteScalar to retrieve the result . . .

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