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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:57:57+00:00 2026-06-10T13:57:57+00:00

I have a table in SQL 2005 that I want to aggregate data from,

  • 0

I have a table in SQL 2005 that I want to aggregate data from, here is an example.

JobName       ProductionCounter       StartDate             EndDate               CounterName        Stage
----------------------------------------------------------------------------------------------------------

200           23                      2012-08-30 13:45:00                          Kilograms          Final
200           2                       2012-08-30 13:45:00                          Bars               Final
    [...]
200           46                      2012-08-30 13:45:00   2012-08-30 17:23:00    Kilograms          Final
200           4                       2012-08-30 13:45:00   2012-08-30 17:23:00    Bars               Final
300           20                      2012-08-30 13:45:00                          Kilograms          1st
300           10                      2012-08-30 18:12:00                          Bars               1st
    [...]
300           40                      2012-08-30 18:12:00   2012-08-30 19:17:00    Kilograms          1st
300           20                      2012-08-30 18:12:00   2012-08-30 19:17:00    Bars               1st

I want to format this into the following


JobName      TotalKilos       TotalBars       StartDate             EndDate               Stage
-----------------------------------------------------------------------------------------------

200          69               6               2012-08-30 13:45:00   2012-08-30 17:23:00   Final
300          60               30              2012-08-30 18:12:00   2012-08-30 19:17:00   1st

This has made me realise I know nothing about SQL. I have tried the following as a start

SELECT JobName, SUM(KiloCounter)
FROM vwOeeInterval
GROUP BY JobName

SELECT JobName, SUM(BarCounter)
FROM vwOeeInterval
GROUP BY JobName

My questions are:

  1. How do I combine these into one query?

  2. How would I query for the columns such as StartDate and Stage? Especially where the End Date
    is not filled in until the job completes?

Any pointers would be much appreciated.

  • 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-10T13:57:59+00:00Added an answer on June 10, 2026 at 1:57 pm

    This is a simple aggregation query. You just need to add the fields that you want:

    SELECT JobName, SUM(KiloCounter) as TotalKilos,
           sum(BarCounts) as TotalBars,
           min(StartDate) as StartDate,
           max(EndDate) as EndDate,
           max(Stage) as Stage 
    FROM vwOeeInterval
    GROUP BY JobName
    

    I am presuming that you know that StartDate, EndDate, and Stage are the same or NULL for all rows with the same job. The aggregation will ignore the NULL values.

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

Sidebar

Related Questions

I have a table in SQL Server 2005 that I want to aggregate data
I have a table that stores data from the county appraisal district. I want
In SQL Server 2005 I have a table with data that looks something like
On MS SQL Server 2005, I have a table that I want to replace.
I have a junction table in my SQL Server 2005 database that consist of
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have an ADOQuery that inserts a record to SQL Server 2005 table that
I use SQL Server 2005. I have a simple logging table that my web
enter code here I have a table on SQL server 2005 with bigint primary
i have table with filmname and actors column in sql server 2005 i want

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.