select "统计行数",字段1,字段2,....
from table
请问统计行数那一部分应该怎么写,表结构已经固定,不能修改且没有自增的字段
select count(*),字段1,字段2,....
from table
OR
select count(*),字段1
from table
group by 字段1
按字段1进行分组,查出每个组的行数。
select count(*) as Totle, 字段1, 字段二, ....
from table
@@ROWCOUNT
返回受上一语句影响的行数。
语法
@@ROWCOUNT
返回类型
integer
注释
任何不返回行的语句将这一变量设置为 0 ,如 IF 语句。
示例
下面的示例执行 UPDATE 语句并用 @@ROWCOUNT 来检测是否有发生更改的行。
UPDATE authors SET au_lname = Jones
WHERE au_id = 999-888-7777
IF @@ROWCOUNT = 0
print Warning: No rows were updated
select count(*) as 行数,字段1,字段2,....
from table
select 字段1,字段2,....
from table
select @@rowcount 行数
SELECT IDENTITY(int, 1,1) AS ID,a,b
from table
select IDENTITY(int, 1,1) AS ID_Num,* into #temp from 表
select * from #temp where ID_Num between 10 and 20
更正:
SELECT IDENTITY(int, 1,1) AS ID,a,b
into #t
from table
select * from #t