日期:2014-05-17 浏览次数:20602 次
select top 3
count(0) c, pubid
from
zsk_question
where
checked = 1
and datediff(d, pubtime, getdate()) <= 7
group by pubid order by c desc
select nick(昵称), jifen(7天内的积分), count_question(7天内的问题数), count_answer(7天内的回答数), count_best(7天内的最佳答案)
SELECT pubid ,SUM([count_question(7天内的问题数)] ) AS [count_question(7天内的问题数)]
,SUM([count_answer(7天内的回答数)]) AS [count_answer(7天内的回答数)]
,SUM([count_best(7天内的最佳答案)]) AS [count_best(7天内的最佳答案)]
,SUM([jifen(7天内的积分)]) AS [jifen(7天内的积分)]
FROM (
SELECT pubid ,1 AS [count_question(7天内的问题数)],0 AS [count_answer(7天内的回答数)],0 AS [count_best(7天内的最佳答案)]
, 10 AS [jifen(7天内的积分)]
from question
where checked = 1
and datediff(d, pubtime, getdate()) <= 7
UNION ALL
SELECT A.pubid ,0 AS [count_question(7天内的问题数)],0 AS [count_answer(7天内的回答数)],1 AS [count_best(7天内的最佳答案)]
,10 [jifen(7天内的积分)]
from answer A INNER JOIN question Q
ON A.ID = Q.overid
where A.checked = 1
and datediff(d, A.pubtime, getdate()) <= 7
UNION ALL
SELECT pubid ,0 AS [count_question(7天内的问题数)],1 AS [count_answer(7天内的回答数)],0 AS [count_best(7天内的最佳答案)]
, 10 AS [jifen(7天内的积分)]
from answer
where checked = 1
and datediff(d, pubtime, getdate()) <= 7
) AS T
GROUP BY pubid
USE test
GO
---->生成表User
--
--if object_id('User') is not null
-- drop table [User]
--Go
--Create table [User]([id] int,[nick] nvarchar(50),[jifen] int)
--Insert into [User]
--Select 1,'test','5'
--Union all Select 2,'test2','10'
---->生成表question
--
--if object_id('question') is not null
-- drop table question
--Go
--Create table question([id] int,[checked]