开发者

SQL how to count all rows up to a max value

I am having trou开发者_运维百科ble counting the number of rows until it reaches a certain PK.

My PK is called id and I want to count all rows until i reach a specified id

I have tried using this query but it doesn't work probably becuase I am using a MySQL table

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

I get this error

Invalid use of group function


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


I would use the following:

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

This will be more efficient as you are only returning one column in a row as opposed to all of them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜