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 8591523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:32:50+00:00 2026-06-11T23:32:50+00:00

how can I get a total count of sheets per change of sheet example:

  • 0

how can I get a total count of sheets per change of sheet

example:

select sheetID,
       ..
from SomeTable

results look something like this:

sheetID
-----------
1000
1000
1000
1000
3000
3000
3000

so I want something like this:

select sheetID,
       count(sheetID) as TotalsheetCount
from SomeTable

I just don’t know how to break the count up per change of sheetID.

So I’d end up with this essentially:

sheetID   TotalsheetCount
--------  -----------
1000          4
1000          4
1000          4
1000          4
3000          3
3000          3
3000          3

so 4 is because there are 4 1000s, 3 because there are 3 3000s. I am wanting to repeat the total count for that sheetID for each row, even though it’s repeating, I want to provide that.

UPDATE, here’s what I did per the replies but I’m getting way too many results now as compoared to the count where I did not add that partition count before

   select MainTable.sheetID,
           COUNT(SomeTable.sheetID)OVER(PARTITION BY SomeTable.sheetID) AS TotalSheetCount
           table2.SomeField1,
           table2.SomeField1
    from MainTable
        join (select distinct Sales.SalesKey from SomeLongTableName_Sales) sales on sales.SheetKey = MainTable.sheetKey
        left outer join Site on MainTable.SiteKey = Site.SiteKey
        join Calendar on sales.Date >= Calendar.StartDate
             and sales.Date < Calendar.EndDate
        group by SomeTable.sheetID

the joins and stuff is more realistic to my real query but formatted for this post to hide real field and table names.

  • 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-06-11T23:32:52+00:00Added an answer on June 11, 2026 at 11:32 pm

    You probably want to use a GROUP BY:

    SELECT sheetID,  COUNT(sheetID) AS TotalsheetCount
    FROM dbo.SomeTable
    GROUP BY sheetID
    

    I am wanting to repeat the total count for that sheetID for each row,
    even though it’s repeating, I want to provide that

    If you’re using at least SQL-Server 2005, you can use a CTE with COUNT + OVER-clause, otherwise use a sub-query:

    WITH CTE AS
    (
       SELECT sheetID,  
          COUNT(sheetID)OVER(PARTITION BY sheetID) AS TotalsheetCount
       FROM SomeTable
    )
    SELECT sheetID, TotalsheetCount FROM CTE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the total count of the number of lines from all
I'm trying to get the total count of employee ids so that I can
How can I get the total physical memory in bytes of my Linux PC?
Hey. How can I get a total number of rows in a file (do
For some reason i can't get the variable 'total' to define at all... I
With Facebook, you can do this: http://api.facebook.com/method/fql.query?format=json&query=SELECT total_count FROM link_stat WHERE url=http://stackoverflow.com OR url=http://stackexchange.com
How can I get the total number of Granny Smith apples? I have tried
I have a select statement that returns two columns: office names and total per
I'm trying to get the total count of facebook likes for links. paste the
I have a written a query to get the total count. But it returns

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.