快捷搜索:

SQL实例进阶-学习sql server2005 step by step(八)

1.SQL2005中row_number( )、rank( )、dense_rank( )、ntile( )函数的用法

(1).row_number( )

先来点数据,先建个表

1 SET NOCOUNT ON

2

3CREATE TABLE Person(

4

5 FirstName VARCHAR(10),

6

7 Age INT,

8

9 Gender CHAR(1))

10

11INSERT INTO Person VALUES ('Ted',23,'M')

12

13INSERT INTO Person VALUES ('John',40,'M')

14

15INSERT INTO Person VALUES ('George',6,'M')

16

17INSERT INTO Person VALUES ('Mary',11,'F')

18

19INSERT INTO Person VALUES ('Sam',17,'M')

20

21INSERT INTO Person VALUES ('Doris',6,'F')

22

23INSERT INTO Person VALUES ('Frank',38,'M')

24

25INSERT INTO Person VALUES ('Larry',5,'M')

26

27INSERT INTO Person VALUES ('Sue',29,'F')

28

29INSERT INTO Person VALUES ('Sherry',11,'F')

30

31INSERT INTO Person VALUES ('Marty',23,'F')

32

33

您可能还会对下面的文章感兴趣: