【问题标题】:SQL how to count all rows up to a max valueSQL如何将所有行计数到最大值
【发布时间】:2011-03-11 09:50:13
【问题描述】:

在达到某个 PK 之前,我无法计算行数。

我的 PK 称为 id,我想计算所有行,直到达到指定的 id

我尝试过使用此查询,但它可能不起作用,因为我使用的是 MySQL 表

select max(count(*)) from news where id=18 group by id

我收到此错误

组函数的使用无效

【问题讨论】:

    标签: mysql sql aggregate-functions mysql-error-1111


    【解决方案1】:

    我会使用以下内容:

    select count(id) from news where id <= 18
    

    这将更有效率,因为您只返回一行中的一列,而不是所有列。

    【讨论】:

      【解决方案2】:
      select count(*) from news where id<=18 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-09
        • 1970-01-01
        • 2020-06-23
        • 1970-01-01
        • 2022-01-14
        • 1970-01-01
        相关资源
        最近更新 更多