|
下面这个SQL 是我重写眼镜 权值排序的,红色部分 是前端传来的数据 ID=120 就是文章的ID。我根据这个ID 去判断向后获取的列表有哪些
BEGIN
declare @now datetime,@_year int,@_month int,@_day int,@_NewsNum int;
set @now = GETDATE();
set @_year=DATEPART(YEAR,@now);
set @_month=DATEPART(MONTH,@now);
set @_day=DATEPART(DAY,@now);
SET @_NewsNum=(
SELECT rowNumber FROM (
select *,ROW_NUMBER() over (order by finalScale1 desc) rowNumber from (
select top 10000 * from
(
select finalScale1=
(
n1.Scale*0+
(
(DATEPART(YEAR,n1.ComeUpTime)-@_year)*365+
(DATEPART(MONTH,n1.ComeUpTime)-@_month)*30+
DATEPART(DAY,n1.ComeUpTime)-@_day
)*3+
n1.Clicked*0
),Id id,
Path path,
Title title,
CONVERT(nvarchar(30),CreatedAt,20) created_at,
HasVideo hasVideo
from dbo.News n1
left join dbo.NavAdTypeNews n2 on n1.Id =n2.News_Id AND n1.Shown=1 AND n2.NavAdType_Id = 4
) as a order by a.finalScale1 desc
) as b ) as c WHERE id=120
);
SELECT * FROM (
select *,ROW_NUMBER() over (order by finalScale1 desc) rowNumber from (
select top 10000 * from
(
select finalScale1=
(
n1.Scale*0+
(
(DATEPART(YEAR,n1.ComeUpTime)-@_year)*365+
(DATEPART(MONTH,n1.ComeUpTime)-@_month)*30+
DATEPART(DAY,n1.ComeUpTime)-@_day
)*3+
n1.Clicked*0
),Id id,
Path path,
Title title,
CONVERT(nvarchar(30),CreatedAt,20) created_at,
HasVideo hasVideo
from dbo.News n1
left join dbo.NavAdTypeNews n2 on n1.Id =n2.News_Id AND n1.Shown=1 AND n2.NavAdType_Id = 4
) as a order by a.finalScale1 desc
) as b ) as c WHERE rowNumber> @_NewsNum AND rowNumber<@_NewsNum+7
END
|
|