私はStackOverflowのデーターダンプで遊んでいます。今、私は、T-SQLの問題を抱えている:T-SQLで2つの異なる列を数えるには?
私は月と年ごとの質問の数とリストを選択することができます:私はWHERE
行×上and tags.tagname = 'scala'
を追加する場合は、私が手
select datepart(year, posts.creationdate) as year,
datepart(month, posts.creationdate) as month,
count(distinct posts.id) as questions
from posts
inner join posttags on posttags.postid = posts.id
inner join tags on tags.id = posttags.tagid
where posts.posttypeid = 1
group by datepart(month, posts.creationdate),
datepart(year, posts.creationdate)
order by datepart(year, posts.creationdate),
datepart(month, posts.creationdate)
すべての "スカラー質問"の数。質問の総数と特定のタグを含む質問の数を同じ結果セット(異なる列)に表示する方法はありますか?
and tags.tagname = 'scala'
を追加すると、月に合計質問数が表示されなくなるため、
これらの結果セットを1つにまとめる方法についてのアイデアはありますか?
ミカエル - 私はあなたがあなたのテーブルを結合することを忘れて一日を参照してくださいだろうと思ったことはありません。 posttags.tagid =(tagname = 'scala'とposttags.tagid = idのタグからIDを選択) –
@ t-clausen.dk。私はしませんでした。サブクエリは、1つの行/値のみを返します。 'scala'のIDは '3143 'なので、サブクエリに値を返すのではなく、' 3143'を使って結合を書くことができます。 http://data.stackexchange.com/stackoverflow/q/107949/ –
もう一度素晴らしいミカエル。私は思った..決して+1を気にしない:) –