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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:43:20+00:00 2026-06-12T05:43:20+00:00

We have a so called evaluation process for new products which is fairly complex.

  • 0

We have a so called evaluation process for new products which is fairly complex. A product is evaluated for different Regions and applications. Afer each evalution step the product gets a new Result score. this score (between 0 to 10) says how far the product is in the process. For each step it stays the same or is increased but never decreased and uneven numbers mark products that failed the evaluation. The highest score is called the products Status.

I no want to Select all products that had an even status (2,4,8,10) at startDate (including that status) and the status at endDate of the time frame.

(I also want to select all new products that entered the proccess in that time frame but I think that can be done easly in a second statement.)

The issue I have is how to include both initial status in the output. Here is my SQL Statement:

SELECT 
  MyTable.product_id, 
  MyTable.REGION, 
  MyTable.SEGMENT,
  Max(MyTable.result) AS NEW_STATUS
  FROM 
     MyTable INNER JOIN (
     SELECT
      product_id, 
      REGION, 
      SEGMENT, 
      Max(result) AS INITIAL_STATUS
    FROM
      MyTable
    WHERE
      DATE <= to_date(:startDate)
    GROUP BY
      product_id, REGION, SEGMENT
    HAVING
      Max(result) IN(2,4,8,10)
   ) initial_status ON MyTable.product_id = initial_status.product_id    
  WHERE
    MyTable.DATE <= to_date(:endDate)
  GROUP BY
    MyTable.product_id, 
    MyTable.REGION, 
    MyTable.SEGMENT;

How can I include initial_status in the output without affecting max/group by?
(is oracle, but I’m no expert so maybe some oracle specific stuff can help)

EDIT:

the data is in a 1 to many relationship. 1 product, many evaluations. each evaluation has an Region, segment, result and evaluation_date (plus other data not relevant here). denormalized here some example data:

product_id    Region    Segment    Result    date
    1           US         AB         2    20.05.2012
    1           EU         TS         4    13.06.2012
    1           US         AB         4    01.09.2012
  234           US         AB         2    09.09.2012

Expected output for above sample with date Range from 26.08.2012 to 21.09.2012:

product_id    Region    Segment    Initial_Status    New_Status
    1            US        AB             2              4
    1            EU        TS             4              4 (this did not change)
  234            US        AB           (null)           2 ( new entry)

I know my current SQL can’t achieve that. especially displaying the values that are new.

  • 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-12T05:43:21+00:00Added an answer on June 12, 2026 at 5:43 am

    Just for documentation I came up with following query. I know it contains certain requirements not asked in the initial question. Some of them are due to deal with faulty data.

    SELECT 
      product_id, 
      REGION, 
      SEGMENT,
      initial_status,
      NEW_STATUS,
      "Comment",
      Count("Comment")  OVER (PARTITION BY 
          "Comment"
        ) "Counter"
    from(
    SELECT DISTINCT
      myTable.product_id, 
      myTable.REGION, 
      myTable.SEGMENT,
      initial_status.initial_status,
      Max(myTable.result) 
        OVER (PARTITION BY 
          myTable.product_id, 
          myTable.REGION, 
          myTable.SEGMENT
        ) NEW_STATUS,
      CASE WHEN initial_status.initial_status <> Max(myTable.result) 
        OVER (PARTITION BY 
          myTable.product_id, 
          myTable.REGION, 
          myTable.SEGMENT
        ) THEN 'Changed' ELSE 'Same' END as "Comment"  
      FROM 
        myTable INNER JOIN (
         SELECT
          product_id, 
          REGION, 
          SEGMENT, 
          Max(result) AS INITIAL_STATUS
        FROM
          myTable
        WHERE
          DATE <= to_date(:startDate)
          OR DATE is null
        GROUP BY
          product_id, REGION, SEGMENT
        HAVING
          Max(result) IN(2,4,8,10)
       ) initial_status 
        ON 
          myTable.product_id = initial_status.product_id
          AND myTable.REGION = initial_status.REGION
          AND (
            myTable.SEGMENT = initial_status.SEGMENT
            OR (myTable.SEGMENT is null AND initial_status.SEGMENT is null)
          )
      WHERE
        myTable.DATE <= to_date(:endDate)
    UNION ALL
    SELECT 
      myTable.product_id, 
      myTable.REGION, 
      myTable.SEGMENT,
      null AS initial_status,
      Max(myTable.result) 
        OVER (PARTITION BY 
          myTable.product_id, 
          myTable.REGION, 
          myTable.SEGMENT
        ) NEW_STATUS,
    'New' As "Comment"
    FROM myTable
    WHERE evaluation_date BETWEEN to_date(:startDate) + 1 AND to_date(:endDate)
    AND stage <> 'Stage 0')
    ORDER BY
        product_id ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wants to access a method in different project. as example i have called
i have table called as Support, which have a field named Name and contains
I have a controller called 'exposures' which I created automatically with the script/generate scaffold
I have a python class called Video, which represents YouTube videos. Given the ID
I have a java script function that i have called on body load mousemove()
Using a .NET TcpClient if I have called an asynchronous BeginRead() on the associated
I have a form with a submit button. I have called a function on
I'm binding a gridview dynamically from a table in my database I have called
In my activity oncreate method, i have called a service using OnStartCommand(). My requirement
I'm working with a dynamic DOM here, and have called the jQuery UI datepicker

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.