如何取得有 group by 的select 语句返回的记录条数?

qyq1973 2004-12-09 12:02:08
比如:
select count(*) as countRec, A, B, C from table where A=9 group by A, B, C
需要获得它返回的记录条数
...全文
154 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jilate 2004-12-09
  • 打赏
  • 举报
回复
同意楼上的
WangZWang 2004-12-09
  • 打赏
  • 举报
回复
select count(*) as [记录条数]
from (Select A, B, C from table where A=9 group by A, B, C) as tbl
qyq1973 2004-12-09
  • 打赏
  • 举报
回复
对是对,但是不和其它数据库兼容
jiang130 2004-12-09
  • 打赏
  • 举报
回复
select count(*) from (select count(*) as countRec, A, B, C from table where A=9 group by A, B, C) as a
vinsonshen 2004-12-09
  • 打赏
  • 举报
回复
Select A, B, C from table where A=9 group by A, B, C
print '记录数='+ cast(@@rowcount as varchar)

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧