我正在尝试运行类似于以下内容的查询
"select * from
(select datepart(wk,date)as week,count(*),platform
from school
where year(date) = 2015
group by datepart(wk,date)) a
full outer join
(select datepart(wk,date) as week,count(*),platform
from school
where year(date) = 2014
group by datepart(wk,date)) b
on b.week = a.week
order by b.week "
因此我多次获得相同的值。
有谁能告诉我这是什么问题......
谢谢
答案 0 :(得分:0)
你错过了小组中的平台:
SELECT *
FROM (
SELECT DATEPART(wk,[date]) AS [week]
,COUNT(*)
,[platform]
FROM [school]
WHERE YEAR([date]) = 2015
GROUP BY DATEPART(wk,[date]), [platform]
) [a]
FULL OUTER JOIN (
SELECT DATEPART(wk,[date]) AS [week]
,COUNT(*)
,[platform]
FROM [school]
WHERE YEAR([date]) = 2014
GROUP BY DATEPART(wk,[date]), [platform]
) [b]
ON [b].[week] = [a].[week]
ORDER BY [b].[week]