更新 Sql排序
时间:2011-03-21 来源:默西塞德
CREATE TABLE [dbo].[CustomerTrack](
[ID] [int] IDENTITY(1,1) NOT NULL,
[CustomerID] [uniqueidentifier] NULL,
[Channel] [int] NULL,
[OrderIndex] [int] NULL,
[Value] [nvarchar](50) NULL,
CONSTRAINT [PK_CustomerTrack] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] --------------- 上表增删改之后,下述脚本更新orderindex with r_SomeTable
as
(
select * , row_number() over(partition by IDCol order by ValueCol) as rnk
from SomeTable
)
update r_SomeTable
set RANKCol = rnk
[ID] [int] IDENTITY(1,1) NOT NULL,
[CustomerID] [uniqueidentifier] NULL,
[Channel] [int] NULL,
[OrderIndex] [int] NULL,
[Value] [nvarchar](50) NULL,
CONSTRAINT [PK_CustomerTrack] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] --------------- 上表增删改之后,下述脚本更新orderindex with r_SomeTable
as
(
select * , row_number() over(partition by IDCol order by ValueCol) as rnk
from SomeTable
)
update r_SomeTable
set RANKCol = rnk
相关阅读 更多 +