--分页
declare @currentPageIndex int --当前页号
set @currentPageIndex=2 --设置当前页号为
select top 10 * from (select row_number() over(order by id desc) as rownumber,*
from test_table)
as testdata where rownumber>10*(@currentPageIndex-1)
只改年月日,时间不变
update bbb set date =( DATEADD(YEAR,DATEDIFF(YEAR,DATE,'2008-1-1'),date))
update bbb set date =( DATEADD(MONTH,DATEDIFF(MONTH,DATE,'2008-1-1'),date))
update bbb set date =( DATEADD(DAY,DATEDIFF(DAY,DATE,'2008-1-1'),date))
重复记录使用row_number()
|
1
2
|
SELECT ROW_NUMBER() OVER ( PARTITION BY name ORDER BY NAME ) as xh_name ,ROW_NUMBER() OVER ( PARTITION BY hey ORDER BY hey ) xh_key, * from bbb |

select * from bbb where hey in
(select a.hey from
(select * from bbb where name in
(select name from bbb group by name having COUNT(name) > 2)) as a
group by a.hey having COUNT(a.hey) > 1)
正常的语句如上,复杂点的编辑后如下,看执行计划,下面的表扫描只有一次,看来应该是下面的语句好
WITH cte AS ( SELECT ROW_NUMBER() OVER ( PARTITION BY name ORDER BY NAME ) xh_name ,
ROW_NUMBER() OVER ( PARTITION BY hey ORDER BY hey ) xh_key, * FROM bbb )
SELECT * FROM cte WHERE xh_name > 2 AND xh_key > 1
浙公网安备 33010602011771号