当前位置: 代码迷 >> Sql Server >> 求显示总行数,该怎么解决
  详细解决方案

求显示总行数,该怎么解决

热度:59   发布时间:2016-04-27 12:25:07.0
求显示总行数
原表A:
ID NAME  
1 张三
2 李四
4 王五

求解count代表无条件的总行数:
ID NAME count 
1 张三 3
2 李四 3

不想采用语句:
Select *,(Select Count(*) Count From A where id<4) From A where id<4

还有其他方法吗?

------解决方案--------------------
SQL code
--> 测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([ID] int,[NAME] varchar(4))insert [test]select 1,'张三' union allselect 2,'李四' union allselect 4,'王五'select * from(select *,COUNT(1)over(partition by 1) as [count] from test)twhere ID<4/*ID    NAME    count-----------------------1    张三    32    李四    3*/
  相关解决方案