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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:15:27+00:00 2026-05-22T02:15:27+00:00

I have a view that looks like this: package_id package_line status_a status_b 1 1

  • 0

I have a view that looks like this:

package_id  package_line  status_a        status_b
1           1             NOT_STARTED     FAILED
1           2             STARTED         STARTED
1           3             FAILED          NOT_STARTED
2           1             COMPLETE        STARTED
2           2             COMPLETE        NOT_STARTED

and so on, for several thousand rows. Status_a and status_b are separate unrelated statuses (in fact they are whether a package executed on system a and on system b).

I need a summary by package_id, to roll up to

   package_id status_a  status_b
   1          FAILED    FAILED
   2          COMPLETE  NOT_STARTED

The rules for combining package lines are

 1. If any package line has failed, the package has failed.
 2. If all package lines are complete, the package is complete.
 3. If all package lines are NOT_STARTED, the package has not started.
 4. Otherwise, the package is started (i.e. a combination of started, not_started, and complete would summarize as STARTED).

So I’m trying to come up with a query to create this summary. I’d love to post a code sample, but I’m really at loss. Presumably I want to GROUP_BY the package_id, but what can I use as an aggregate function that would allow me to apply the rules listed?

If it helps, I do have control over how the statuses are reported at the package line level, so I could report a numeric status (though I like having it human readable just for sanity).

  • 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-22T02:15:27+00:00Added an answer on May 22, 2026 at 2:15 am

    Try this (same for status_b):

    SELECT package_id,
           CASE WHEN FAILED_COUNT > 0 THEN 'FAILED'
                WHEN COMPLETE_COUNT = ALL_COUNT THEN 'COMPLETE'
                WHEN NOT_STARTED_COUNT = ALL_COUNT THEN 'NOT_STARTED'
                ELSE 'STARTED'
           END status_a
    FROM (            
    SELECT package_id,
         COUNT(status_a) ALL_COUNT,
         SUM(CASE WHEN status_a = 'FAILED' THEN 1 ELSE 0 END) FAILED_COUNT,
         SUM(CASE WHEN status_a = 'COMPLETE' THEN 1 ELSE 0 END) COMPLETE_COUNT,
         SUM(CASE WHEN status_a = 'NOT_STARTED' THEN 1 ELSE 0 END) NOT_STARTED_COUNT,
         SUM(CASE WHEN status_a = 'STARTED' THEN 1 ELSE 0 END) STARTED_COUNT
     FROM table
    GROUP BY package_id
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view model that looks like this public class ViewModelRound2 { public
I have a list view that looks like this and that's its code ..
I have a view hierarchy that looks something like this: UIView (A) UIView >
Here goes: I have a view that looks like this: public interface IAddressView {
I'm using SQL Server 2008 and I have a view that looks like this:
This is interesting. I have some view code that looks like this: <%= @cause.updates.each
I have a view that looks like this: def login(request): ... # some variables
So I have a View that looks like this. //base class var SelectListView =
I have this Tree View that looks like this: <TreeView Grid.Column=0 Grid.Row=2 MinHeight=100 MinWidth=100
I have a view that looks like this: @model List<int> @{ ViewBag.Title = Index;

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.