2011年のStackOverflowでの1日あたりのAndroidの質問の数を返す次のクエリがあります。2011年に尋ねられたすべての質問の合計を取得したいと思います。このためにを使用してROLLUP
います。
select
year(p.CreationDate) as [Year],
month(p.CreationDate) as [Month],
day(p.CreationDate) as [Day],
count(*) as [QuestionsAskedToday]
from Posts p
inner join PostTags pt on p.id = pt.postid
inner join Tags t on t.id = pt.tagid
where
t.tagname = 'android' and
p.CreationDate > '2011-01-01 00:00:00'
group by year(p.CreationDate), month(p.CreationDate),day(p.CreationDate)
with rollup
order by year(p.CreationDate), month(p.CreationDate) desc,day(p.CreationDate) desc
これは出力です:
2011年の各日に行われたすべての質問の合計は、QuestionsAskedToday列自体に表示されます。
エイリアスを使用して新しい列にロールアップを表示する方法はありますか?