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

  • SEARCH
  • Home
  • 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 7046833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:41:51+00:00 2026-05-28T02:41:51+00:00

I have a table with columns: MONTH , YEAR , PROJECT_ID , STATUS .

  • 0

I have a table with columns: MONTH, YEAR, PROJECT_ID, STATUS.

Status can be:

  • R (red).
  • A (amber).
  • G (green).
  • N (not started).
  • C (completed).

I want to know how many projects completed in a given month i.e. :

where STATUS changed from anything that is NOT C to C;

It sounds simple…!

It’s easy to find when any given project completed with:

SELECT TOP 1 MONTH,YEAR,PROJECT_ID FROM Table WHERE PROJECT_ID=9236 AND RAG='C'
  ORDER BY YEAR ASC, MONTH ASC

But given year = 2011 and month = 8 (for example), I have no idea how to find the number of projects that had status='C' for the first time that month. Any ideas?

Edit: projects are still included as rows with status='C' after they complete, so I can’t just count the Cs as that will return the number of projects that completed in this AND previous months (hence the chronological ordering and select top 1).

Sample data for 10/2010 to 01/2011 months:

Month | Year | Project | Status
-------------------------------
10    | 2010 | A       | G
11    | 2010 | A       | C
12    | 2010 | A       | C
1     | 2011 | A       | C
10    | 2010 | B       | R
11    | 2010 | B       | R
12    | 2010 | B       | R
1     | 2011 | B       | R
10    | 2010 | C       | G
11    | 2010 | C       | G
12    | 2010 | C       | G
1     | 2011 | C       | C
10    | 2010 | D       | A
11    | 2010 | D       | C
12    | 2010 | D       | C
1     | 2011 | D       | C

^ Projects A and D was completed in 11/2010. Project B hasn’t changed to completed in any of the four months shown. Project C was completed in 01/2011. {Month,Year,Project} is the primary key.

So, inputs and outputs would be:

10/2010 => 0
11/2010 => 2 (because of A and D)
12/2010 => 0
1/2011 => 1 (because of C)
  • 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-28T02:41:52+00:00Added an answer on May 28, 2026 at 2:41 am

    This will give you the counts you are looking for

    select p1.mm,p1.yyyy,COUNT(*)
    from projs p1
    join (select projid,MIN(yyyy*100+mm) as closedOn from projs 
          where stat='c' group by projId) xx 
          on xx.projId=p1.projId and p1.yyyy*100+p1.mm=xx.closedOn
    where p1.stat='c' 
    group by p1.mm,p1.yyyy
    

    The inner query determines the date the project closed, so you are finding all projects which closed this month…

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

Sidebar

Related Questions

I have a table with a year and month in different columns, and I
I have a table that has columns YEAR and MONTH, which are varchars, which
i have to store year and month in my table with two other columns
I have table with 3 columns A B C. I want to select *
I have a table with columns ID, DateStamp and the ID need not be
I have a birthdate, year, month, day columns where columns year,month,day are foreign key
I have a postgres table that looks in part like: Year | Month |
I have a mysql table with year ( YEAR(4) ) and month ( TINYINT
I have a DataTable with multiple columns including AccountNumber, Year, and Month. I am
I have 2 tables. Table Accs contains 9 million rows (3 columns: acc_id, month,

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.