Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6211475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:20:38+00:00 2026-05-24T06:20:38+00:00

I am playing with the StackOverflow datadump. Now I have a T-SQL Problem: I

  • 0

I am playing with the StackOverflow datadump. Now I have a T-SQL Problem:

I can select a list with the number of questions per month and year with:

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)

If I add and tags.tagname = 'scala' on the WHERE-row, then I get the number of all “scala-questions”. Is there any way I can show both the total number of questions and the number of questions containing a specific tag in the same result set (in different columns).

Because when I add the and tags.tagname = 'scala' I can no longer see the total number of questions per month.

Any ideas on how I can unit these resultsets into one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:20:40+00:00Added an answer on May 24, 2026 at 6:20 am

    If you use left outer join against posttags, count(posttags.tagid) will only count non null values. And since the left outer join only contain scala tags, you can skip the distinct in count(distinct posts.id).

    select datepart(year, posts.creationdate) as year,
           datepart(month, posts.creationdate) as month,
           count(*) as questions,
           count(posttags.tagid) as sc
    from posts
      left outer join posttags
        on posttags.postid = posts.id and
           posttags.tagid = (select id
                             from tags
                             where tagname = 'scala')
    where posts.posttypeid = 1
    group by datepart(month, posts.creationdate),
             datepart(year, posts.creationdate)
    order by datepart(year, posts.creationdate),
             datepart(month, posts.creationdate)
    

    Try here: https://data.stackexchange.com/stackoverflow/q/107948/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Playing with log4net, I have seen the possibility to use a per-thread stack of
I'm playing a little bit with the new StackOverflow API . Unfortunately, my JSON
Just playing around with the now released Silverlight 2.0. I'm trying to put a
I was playing with the Stack Exchange Data Explorer and ran this query: https://data.stackexchange.com/stackoverflow/query/2820/rising-stars-top-50-users-ordered-on-rep-per-day
I was playing around with a Python-based HTML parser and parsed Stackoverflow. The parser
I playing around with the sftp example from here: Stackoverflow: twisted conch filetransfer I
I know there have been a lot of questions about Entity Framework doing cross
I have searched StackOverflow and cannot find a situtation like mine. I am using
I've edited this post to better fit the scope of Stackoverflow: I have very
I have been playing with the Facebook iOS API the past days and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.