开发者

How can I get the rows along with row count in SQL?

I have written the following query:

select 
    *, 
    count(pk_id) 开发者_如何学Goas row_count
from employee 
group by 
    pk_id

But I am not getting 1 as the row_count value for every column. How can I get the total number of rows returned as the result of the query? Can someone please help?

And one more thing is I don't want to write any subquery :(


Have you considered either just counting the rows as you receive them in whatever's consuming this result set, or just using FOUND_ROWS? Is there some reason you need the rowcount to appear as a column in the result set?


Try with:

select 
    *, 
    count(*) as row_count
from employee 
group by 
    pk_id
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜