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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:29:49+00:00 2026-06-17T23:29:49+00:00

I have a table in the ORACLE database, details below: ——————————————– | FRUITS |

  • 0

I have a table in the ORACLE database, details below:

--------------------------------------------
|                  FRUITS                  |
--------------------------------------------
| FRUIT_NAME | GROWTH_TIME | GROWTH_PLACE  |
--------------------------------------------
|      melon |        0600 |        shelf1 |
|      melon |        0630 |        shelf1 |
|      melon |        0700 |        shelf1 |
|      melon |        0730 |        shelf1 |
|      melon |        0800 |        shelf1 |

|     orange |        0600 |        shelf5 |
|     orange |        0630 |        shelf5 |
|     orange |        0700 |        shelf5 |
|     orange |        0730 |        shelf5 |
|     orange |        0800 |        shelf5 |
|     orange |        0830 |        shelf5 |
|     orange |        0900 |        shelf5 |
|     orange |        0930 |        shelf5 |
|     orange |        1000 |        shelf5 |

|     orange |        1200 |        shelf5 |
|     orange |        1230 |        shelf5 |
|     orange |        1300 |        shelf5 |
|     orange |        1330 |        shelf5 |
|     orange |        1400 |        shelf5 |

|      apple |        0600 |        shelf3 |
|      apple |        0630 |        shelf3 |
|      apple |        0700 |        shelf3 |
|      apple |        0730 |        shelf3 |
|      apple |        0800 |        shelf3 |
--------------------------------------------

and I would like to get results like these below:

--------------------------------------------
| FRUIT_NAME | GROWTH_TIME | GROWTH_PLACE  |
--------------------------------------------
|      melon |   0600-0800 |        shelf1 |

|     orange |   0600-1000 |        shelf5 |
|     orange |   1200-1400 |        shelf5 |

|      apple |   0600-0800 |        shelf3 |

or like these:

-------------------------------------------------------------------
| FRUIT_NAME | GROWTH_START_TIME | GROWTH_END_TIME | GROWTH_PLACE |
-------------------------------------------------------------------
|      melon |              0600 |            0800 |       shelf1 |

|     orange |              0600 |            1000 |       shelf5 |
|     orange |              1200 |            1400 |       shelf5 |

|      apple |              0600 |            0800 |       shelf3 |

There is a small gap in the ORANGE case (between 1000 and 1400) and this is still the same shelf but with a small gap in time. It happens but I don’t know how to solve this problem.

  • 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-17T23:29:50+00:00Added an answer on June 17, 2026 at 11:29 pm

    you can solve this by analytics:

    SQL> select fruit_name, min(growth_time) || '-' || max(growth_time) growth_time, growth_place
      2    from (select fruit_name, growth_place, growth_time,
      3                 max(grp) over(partition by fruit_name, growth_place order by growth_time) grp
      4             from (select fruit_name, growth_time, growth_place,
      5                          case
      6                            when to_date(lag(growth_time, 1)
      7                                   over(partition by fruit_name, growth_place order by growth_time), 'hh24mi')
      8                                 < to_date(growth_time, 'hh24mi') - (30/1440)
      9                            then
     10                              row_number() over(partition by fruit_name, growth_place order by growth_time)
     11                            when row_number() over(partition by fruit_name, growth_place order by growth_time) = 1
     12                            then
     13                              1
     14                          end grp
     15                      from fruits))
     16   group by fruit_name, growth_place, grp
     17   order by fruit_name, growth_time
     18  /
    
    FRUIT_ GROWTH_TIME                              GROWTH
    ------ ---------------------------------------- ------
    apple  0600-0800                                shelf3
    melon  0600-0800                                shelf1
    orange 0600-1000                                shelf5
    orange 1200-1400                                shelf5
    

    i.e. first we break the result set into groups where a group is defined as contigious dates for a given fruut/shelf.

    We do this by checking the prior date and seeing if its < the current rows date – 30 minutes with

    lag(growth_time, 1) over (partition by fruit_name, growth_place order by growth_time)
    

    from this we can derive groups where the prior row was over 30 minutes older that this row:

    SQL> select fruit_name, growth_time, growth_place,
      2         case
      3           when to_date(lag(growth_time, 1)
      4                over(partition by fruit_name, growth_place order by growth_time), 'hh24mi')
      5                < to_date(growth_time, 'hh24mi') - (30/1440)
      6           then
      7             row_number() over(partition by fruit_name, growth_place order by growth_time)
      8           when row_number() over(partition by fruit_name, growth_place order by growth_time) = 1
      9           then
     10             1
     11         end grp
     12    from fruits;
    
    FRUIT_ GROW GROWTH        GRP
    ------ ---- ------ ----------
    apple  0600 shelf3          1
    apple  0630 shelf3
    apple  0700 shelf3
    apple  0730 shelf3
    apple  0800 shelf3
    melon  0600 shelf1          1
    melon  0630 shelf1
    melon  0700 shelf1
    melon  0730 shelf1
    melon  0800 shelf1
    orange 0600 shelf5          1
    orange 0630 shelf5
    orange 0700 shelf5
    orange 0730 shelf5
    orange 0800 shelf5
    orange 0830 shelf5
    orange 0900 shelf5
    orange 0930 shelf5
    orange 1000 shelf5
    orange 1200 shelf5         10
    orange 1230 shelf5
    orange 1300 shelf5
    orange 1330 shelf5
    orange 1400 shelf5
    

    now we just assign the group to each row with a max() analytic:

    SQL> select fruit_name, growth_place, growth_time,
      2         max(grp) over(partition by fruit_name, growth_place order by growth_time) grp
      3    from (select fruit_name, growth_time, growth_place,
      4                 case
      5                 when to_date(lag(growth_time, 1)
      6                        over(partition by fruit_name, growth_place order by growth_time), 'hh24mi')
      7                      < to_date(growth_time, 'hh24mi') - (30/1440)
      8                 then
      9                   row_number() over(partition by fruit_name, growth_place order by growth_time)
     10                 when row_number() over(partition by fruit_name, growth_place order by growth_time) = 1
     11                 then
     12                   1
     13               end grp
     14          from fruits);
    
    FRUIT_ GROWTH GROW        GRP
    ------ ------ ---- ----------
    apple  shelf3 0600          1
    apple  shelf3 0630          1
    apple  shelf3 0700          1
    apple  shelf3 0730          1
    apple  shelf3 0800          1
    melon  shelf1 0600          1
    melon  shelf1 0630          1
    melon  shelf1 0700          1
    melon  shelf1 0730          1
    melon  shelf1 0800          1
    orange shelf5 0600          1
    orange shelf5 0630          1
    orange shelf5 0700          1
    orange shelf5 0730          1
    orange shelf5 0800          1
    orange shelf5 0830          1
    orange shelf5 0900          1
    orange shelf5 0930          1
    orange shelf5 1000          1
    orange shelf5 1200         10
    orange shelf5 1230         10
    orange shelf5 1300         10
    orange shelf5 1330         10
    orange shelf5 1400         10
    

    now all that’s left was the final group by on the GRP to get the final answer.

    • 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 an Oracle database) just like below: department ---------- Finance
I have two tables (fruit_cost and fruit_availability) in oracle database, details below: fruit_cost looks
we have a table in an Oracle Database which contains a column with the
I have a table in an Oracle Database that has, among others, a DATE
I have a table in Oracle 11.2 database. I want the database to run
I have created a table on an Oracle 10g database with this structure :
I have two columns(column1, column2) in my oracle database table named as demo .
I have 3 columns in Oracle database having table mytable and i want records
We have a Oracle 9i database and OrderDetails table which has a column to
I have an oracle 10g database that has 2 tables: a REBATES table, and

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.