首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-06-13 
求显示总行数原表A:IDNAME1张三2李四4王五求解count代表无条件的总行数:IDNAMEcount1张三32李四3不想采用

求显示总行数
原表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*/ 

热点排行