/*单独查询用户表, 分页,显示资源数和点赞数 */
DECLARE @count INT,
@pageindex INT,
@count1 INT
SET @count = 6
SET @pageindex = 0
SET @count1 = 3
SELECT
top ( @count ) UserAccount.NickName,
UserAccount.HeadPhoto,
( SELECT count( id ) FROM UserAccount ) AS count
FROM
UserAccount
WHERE
ID NOT IN ( SELECT top ( @pageindex * @count ) ID FROM UserAccount ) BEGIN
DECLARE
@a INT,
@error INT DECLARE
@temp VARCHAR ( 50 )
SET @a = 1
SET @error = 0 DECLARE
order_cursor CURSOR FOR (
SELECT
top ( @count ) UserAccount.NickName
FROM
UserAccount
WHERE
ID NOT IN ( SELECT top ( @pageindex * @count ) ID FROM UserAccount )
) OPEN order_cursor FETCH next
FROM
order_cursor INTO @temp
WHILE
@@FETCH_STATUS = 0 BEGIN
SELECT
top ( @count1 ) UserAccount.NickName,
UserAccount.HeadPhoto,
StandardResources.ID,
StandardResources.UpdateTime,
StandardResources.CoverImg,
( SELECT count( StandardResources.ID ) FROM StandardResources WHERE StandardResources.UploaderID = @temp ) AS IDAll,
( SELECT sum( StandardResources.GiveLike ) FROM StandardResources WHERE StandardResources.UploaderID = @temp ) AS GiveLikeAll
FROM
UserAccount,
StandardResources
WHERE
UserAccount.NickName = @temp
AND UserAccount.NickName = StandardResources.UploaderID
GROUP BY
UserAccount.NickName,
UserAccount.HeadPhoto,
StandardResources.ID,
StandardResources.CoverImg,
StandardResources.UpdateTime
ORDER BY
StandardResources.UpdateTime DESC;
SET @a = @a + 1
SET @error = @error + @@ERROR FETCH next
FROM
order_cursor INTO @temp
END CLOSE order_cursor DEALLOCATE order_cursor
END
go
/*单独资源表和关注表,显示资源总数,点赞和是否关注*/
declare @count int,@pageindex int
set @count=3
set @pageindex=1
begin
declare @a int,@error int
declare @temp varchar(50)
set @a=1
set @error=0
declare order_cursor cursor
for (
SELECT top(@count)
UserAccount.NickName
FROM
UserAccount
WHERE
ID NOT IN ( SELECT top(@pageindex*@count) ID FROM UserAccount )
)
open order_cursor
fetch next from order_cursor into @temp
while @@FETCH_STATUS = 0
begin
SELECT
(@temp) as curdesigner,
( SELECT count( ID ) FROM StandardResources WHERE UploaderID = @temp ) AS ProductsAll,
( SELECT sum( GiveLike ) FROM StandardResources WHERE UploaderID = @temp ) AS GiveLikeAll,
( SELECT count(ID) FROM [AttentionPool] WHERE NickName ='偏执的小冰' and AttentionNickName=@temp) AS Beattentionedbool
set @a=@a+1
set @error= @error + @@ERROR
fetch next from order_cursor into @temp
end
close order_cursor
deallocate order_cursor
end
go