Find the continuous block of numbers - using queries

Hi all

I have a vision that has places available for sale. View has a row for each available place. I'll try to find block of seats in places like this

Bench dry (from - to) Qty.
A1 1 2 17 - 18
A3 4 2 90 - 91
A3 4 4 94 - 97
A8 14 2 45 - 46
A8 14 49 - 51 3
A8 14 54 - 58 5
14 61 - 62 2 A8

-Table and data Script-
create table (available)
s varchar2 (5).
rows1 varchar2 (5).
seat number (3)
);

insert into available (sec, rows1, seat) values ('A1', '1', 17);
insert into available (sec, rows1, seat) values ('A1', '1', 18);
insert into available (sec, rows1, seat) values ('3', '4', 90);
insert into available (sec, rows1, seat) values ('3', '4', 91);
insert into available (sec, rows1, seat) values ('3', '4', 94);
insert into available (sec, rows1, seat) values ('3', '4', 95);
insert into available (sec, rows1, seat) values ('3', '4', 96);
insert into available (sec, rows1, seat) values ('3', '4', 97);

insert into available (sec, rows1, seat) values ('A8', '14', 45);
insert into available (sec, rows1, seat) values ('A8', '14', 46);
insert into available (sec, rows1, seat) values ('A8', '14', 49);
insert into available (sec, rows1, seat) values ('A8', '14', 50);
insert into available (sec, rows1, seat) values ('A8', '14', 51);
insert into available (sec, rows1, seat) values ('A8', '14', 54);
insert into available (sec, rows1, seat) values ('A8', '14', 55);
insert into available (sec, rows1, seat) values ('A8', '14', 56);
insert into available (sec, rows1, seat) values ('A8', '14', 57);
insert into available (sec, rows1, seat) values ('A8', '14', 58);
insert into available (sec, rows1, seat) values ('A8', '14', 61);
insert into available (sec, rows1, seat) values ('A8', '14', 62);
----------------------------------------------------
I'm going in a position so far

Select sec, seat, rows1, next_seat, (next_seat - seat) gap
de)
Select dry, seat, rows1, LEAD (seat) OVER (PARTITION BY s, order of rows1 per seat) next_seat
of available
)

Thanks in advance for you help,

Ngoyi,

Houston-Texas
with t1 as (
            select  sec,
                    rows1,
                    seat,
                    case lag(seat) over(partition by sec,rows1 order by seat)
                      when seat - 1 then 0
                      else 1
                    end start_of_group
              from  availables
           ),
     t2 as (
            select  sec,
                    rows1,
                    seat,
                    sum(start_of_group) over(partition by sec,rows1 order by seat) grp
              from  t1
           )
select  sec "Sec",
        rows1 "Row",
        min(seat) || ' - ' || max(seat) "Seat (From-To)",
        max(seat) - min(seat) + 1 "Qty"
  from  t2
  group by sec,
           rows1,
           grp
  order by sec,
           rows1,
           grp
/

Sec   Row   Seat (From-To)              Qty
----- ----- -------------------- ----------
A1    1     17 - 18                       2
A3    4     90 - 91                       2
A3    4     94 - 97                       4
A8    14    45 - 46                       2
A8    14    49 - 51                       3
A8    14    54 - 58                       5
A8    14    61 - 62                       2

7 rows selected.

SQL>  

SY.

Tags: Database

Similar Questions

  • Where can I find the "recent pages" selection that used to be next door buttons 'Back-Forward "?

    Where can I find the "recent pages" selection that used to be next door buttons 'Back-Forward "?

    Make a right click the back / front button.

  • Try to find the extended ICA if I use a graph on a t shirt, anyone know?

    Try to find the extended ICA if I use a graph on a t shirt, anyone know?

    Hello

    In the FAQ - Adobe Stock helps | Frequently asked questions

    Adobe Stock offers licenses allowing licensees to sell products or services based on an image?

    At the moment, Adobe Stock only provides standard licenses, allowing the licensee to use the images only for illustration purposes.

    Licenses are available via Fotolia - sizes and licenses

    ~ David

  • Hi, I would like to know, where can I find the light Difuse filter that used to be under the CC destort filters-PS (was in all previous versions) - or can I download it somewhere?

    Hi, I would like to know, where can I find the light Difuse filter that used to be under the CC destort filters-PS (was in all previous versions) - or can I download it somewhere?

    Filter > filter Gallery

  • find the right backup of cloning using up the time option

    Hello

    I'm trying to create a script to find out what files to backup (backup rman, rman backup control file and archivelogs) are needed to create a clone of production data base lets say for 1 month ago or two weeks ago.

    My backups are marked, performed on the disk, but a night job takes the disk backup files and moves them to tape.
    So, before I can restore correct correct tape files, I need to know what files to backup should I restore a band.

    I could start the clone and she'll tell me it cannot find the files of backup that is named xxx, yyy and it will eventually error and output, but I find the files.
    The idea is to find the files before the script (script clone) could not find the right files.

    I tried to use the v$ element_sauvegarde, v$ backup_files equivalent rc_ view (s) and tried to join them, but I couldn't find the join columns. I tried stamp column. This gives me some information so I can find the files, but I need to know the approximate duration of the backup.

    So my question is: how RMAN queries it sees? (v$ backup %) I couldn't find a link to foreign key between tables.
    Here is the result of what I managed to find, but I have to give the approximation of 1 hour (1 hour before NMR files have been generated and 1 h after) so I could find the controlfile files and the archivelogs rman backup files.


    'BACKUP' 'BS_TYPE' 'PKEY' 'STAMP' 'RMNFILE' 'STATUS' 'TAG.
    "BACKUP SET" "ARCHIVED LOG" 2568 751143608 ' / bckploc/514_2576.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "ARCHIVED LOG" 2566 751143608 ' / bckploc/514_2575.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "ARCHIVED LOG" 2567 751143607 ' / bckploc/514_2574.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "ARCHIVED LOG" 2569 751143607 ' / bckploc/514_2573.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "ARCHIVED LOG" 2570 751143633 ' / bckploc/514_2577.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "DATA file" 2571 751143635 ' / bckploc/514_2581.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "DATA file" 2572 751143635 ' / bckploc/514_2580.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "DATA file" 2573 751143635 ' / bckploc/514_2579.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "DATA file" 2574 751143635 ' / bckploc/514_2578.rmn "'AVAILABLE'"DB_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "ARCHIVED LOG" 2575 751143711 ' / bckploc/514_2582.rmn "'AVAILABLE'"ARCH_DAILY_BACKUP_14052011_1900 ".
    "BACKUP SET" "DATA file" 2576 751143715 ' / bckploc/c-3567074004-20110514-00 '"AVAILABLE" ' TAG20110514T190155' ".

    Any suggestions are appreciated.
    Thank you
    Daniel

    Hello

    I tried to use the v$ element_sauvegarde, v$ backup_files equivalent rc_ view (s) and tried to join them, but I couldn't find the join columns. I tried stamp column. This gives me some information so I can find the files, but I need to know the approximate duration of the backup.
    So my question is: how RMAN queries it sees? (v$ backup %) I couldn't find a link to foreign key between tables.

    If your question is only to reach the point of view.
    Then a tip: you should always join columns (STAMP and COUNTY)

    for example

    bs_stamp
    bs_count 
    
    SET_STAMP
    SET_COUNT
    
    SELECT BP.RECID,
      BP.STAMP,
      BP.RECID,
      BS.RECID,
      BP.SET_STAMP,
      BP.SET_COUNT,
      PIECE#,
      COPY#,
      STATUS,
      BP.COMPLETION_TIME,
      HANDLE,
      BS.CONTROLFILE_INCLUDED,
      BS.BACKUP_TYPE,
      TAG,
      DEVICE_TYPE,
      MEDIA,
      BYTES,
      COMPRESSED
    FROM V$BACKUP_PIECE BP,
      V$BACKUP_SET BS
    WHERE HANDLE IS NOT NULL
    AND BS.SET_STAMP   = BP.SET_STAMP
    AND BS.SET_COUNT   = BP.SET_COUNT;
    
    SET_STAMP  SET_COUNT  COMPLETION_TIME           HANDLE                                                                            CONTROLFILE_INCLUDED TAG
    ---------  ------     ------------------------- --------------------------------------------------------------------------------- --------------------  -------------------
    751030325  109        13/05/11                  +FRA/db10g/backupset/2011_05_13/annnf0_backup_full_0.379.751030327                NO                   BACKUP_FULL         
    
    SELECT FILE_TYPE, FILE_TYPE, STATUS, F_NAME
    FROM V$BACKUP_FILES
    WHERE BS_STAMP = 751030325  AND BS_COUNT= 109;
    
    FILE_TYPE                        STATUS           FNAME
    -------------------------------- ---------------- ------------------------------------------------------------------
    ARCHIVED LOG
    ARCHIVED LOG
    ARCHIVED LOG
    ARCHIVED LOG
    PIECE                            AVAILABLE        +FRA/db10g/backupset/2011_05_13/annnf0_backup_full_0.379.751030327   
    

    In this example, I have 4 archivelogs in the backuppiece.

    I hope this can help you

    See you soon,.
    Levi Pereira

  • Find the appropriate block size?

    Hi all

    I think this might be a simple question, how to find the block size that is appropriate for the construction of a database for a specific application?

    I had always seen default 8K block size is used everywhere (about 300-350 databases I've seen so far)... but why and how they believe this block size blindly before creating the production database.

    Also in the way the parameters of memory are finalized before creating the database?

    -Yasser

    YasserRACDBA wrote:
    OK I understand, but how will comparative analysis for the examination does not block size?

    I mentioned BLINDLY word because before implementation into production, how s/n allows to find the block size that is appropriate for this application.

    Well, as I said, it needs comparative analysis. And if you are not able to do it, the best is to stick to the default size. Read more intensive databases may need some play with the size of the block, but this summary is not authoritative at all, at least not from me. So I say to be on the safeside, by default would help you.
    >

    Right now I have no clear idea on the database of benchmarking, can you please help with this if you have done this by hand before it please...

    Charles and Greg presented very good test cases showing that using 8k is the most optimal choice in most of the cases.
    

    Once again my bad luck that I lost this post before having a look. Are there opportunities to find these test cases?

    See this summary made by JL on his blog,
    http://jonathanlewis.WordPress.com/2008/07/19/block-sizes/

    HTH
    Aman...

  • I can't find the code 39 fonts to use in mac bar

    I need to print labels that contain 39 barcode fonts. How to install on mac mini?

    You can get a legal copy of police in barcode 39 herefree. Make sure you read the title, using the Code 39 barcode fonts. You can also get it here.

    For the first link above, they give you two choices to download the font. DO NOT operate the link recommended . Unless you like adware as well as what you can download from a site of garbage like download.com. The other link will download the police directly. It also comes with a bunch of junk. Throw the INSTALL.exe file. The rest of it in the subfolder are examples. The only thing of real importance is the .ttf font. Alternatively, use the new .otf (OpenType) fonts.

    The police made the code bar itself. If you want the numbers to appear below, you must do so separately. As with the standard MICR font. Or you can use an easy to read font such as Courier (Courier in particular because it is a monospaced font).

  • How to find the yahoo flickr Photo password used to download photos from the Photo app?

    I have 151 000 pictures on Flickr that were loaded from Iphoto, then more recently the Apple Photo app on my imac.

    I can't open a session using a browser because the browser (Chrome) has lost the password of his records.

    How to find the password that the Photo is using app?

    You can not extract the code to access from iPhoto or Photo. I could go to the Web of Flickr site and see what password recovery options they offer for your account.

  • Find the difference between two numbers (DBL)

    Hi all

    Is there a function in labview other than the subtraction function that can find the difference between the two numbers given?

    Thank you

    Davidson


  • Double-click the object of front panel to find the terminal block diagram

    Hello world. I don't know why, if I double click on an object to front panel, labview opens the front tab customize, instead of finding control in block diagrams, which would be the normal behavior, as I read in http://labviewwiki.org/Tips_and_tricks#Debugging.

    I tried to reset the initial Setup by renaming the file LabVIEW.ini, but it doesn't seem to work.

    Do you know how double-click the object on the front panel and locate the?

    Thanks in advance!

    Guille.

    Did you restart LabVIEW after you rename the file labview.ini?

    There is an option (Tools... options...... general façade... 'Open the editor control with double click').

    It always seems to be set in your case.

  • How can I find the appropriate program I should use to open a file downloaded from the internet?

    I saved an acknowledgement of the internet to a file on my computer so I could print later, now when I try to open my computer asks me what program to use.  Any program I try it says that it is not able to open the file. How to find the right program to open my file?

    Hi Grace,

    I understand that you are facing problems with opening a file in your computer.

    We need more information to help you in a better way.

    1. What is the file extension of the file you're trying to open?
    2 is the issue limited to this file?
    3. are you able to open the file in Internet Explorer?

    Your computer would not program to open that particular file format.

    You can see the following articles for reference.

    Open a file or folder


    http://Windows.Microsoft.com/en-in/Windows-Vista/open-a-file-or-folder

    Change the program that opens a type of file


    http://Windows.Microsoft.com/en-in/Windows-Vista/change-the-program-that-opens-a-type-of-file

    Please respond with the required information and we will be happy to help you.

  • An error occurred during the renewal of the Loopback Pseudo-Interface 1: the system cannot find the specified file. I use ipconfig /renew6.

    Hi all

    I use version 2.1 of WINPE. It works with ipv4 network services.

    I have a "Windows2008R2" machine in my network. In this server I am running a DHCPv6 server in my network. This server is the allocation of IPv6 addresses to all computers that have the OS Vista and Win7, etc (for vista and above).

    But I'm not able to receive the ipv6 address for winpe2.1 pc which is my test pc.

    What are the basic things I should do to receive the IPv6 ip address.

    If you please suggest me that how I can solve this problem.

    I tried to have run the command as "ipconfig /renew6" but he throwed an error

    An error occurred during the renewal of the Loopback Pseudo-Interface 1: the system cannot find the specified file.

    It is very urgent for me. I ask if anyone knows the steps so that the WINPE2.1 system get IPV6 will be appreciated.

    Thank you very much.

    Andy

    http://www.Microsoft.com/windowsserver2008/en/us/community.aspx

    They will help you in the community of Windows Server above with your questions.

    See you soon.

    Mick Murphy - Microsoft partner

  • Error message "an error the system cannot find the file specified" when you use Bitlocker

    Original title: Bitlocker to go not accessible by car usb

    Here's the short of it: I decided to use Bitlocker To Go on my USB drive, and while he was to encrypt the drive I plugged a USB DVD - RW drive (it

    s a netbook) and then I got an error message in the Bitlocker program that says "an error the system cannot find the file specified."  I closed the error message and open the Bitlocker Unlock program, put my password and press on unlock and now it only that sit there and spin and the light flashes on my Batman of Seagate HARD drive as it is accessed.  The internal data of the car do not make the same sound, as he did while he was being... just encryption sounds like there are in an infinite loop.  The disc is good and has no errors, and I scanned with SeaTools.  I have a lot of important data on this drive, and I really don't want to lose anything.  Help!

    Hello 5thgear,

    Thank you for the question!

    I'm sorry to know that have problems you with Bitlocker. I get it right you get an error message "an error the system cannot find the file specified" when you run the bitlocker encryption.

    I need to ask you a question to help you best.

    Were there any changes (hardware or software) to the computer before the show?

    Click on the link below.

    http://blogs.technet.com/b/ASKCORE/archive/2010/08/04/issues-resulting-in-BitLocker-recovery-mode-and-their-resolution.aspx

    Answer to us if you are having problems with bitlocker or any other issue of Windows, and I'd be happy to help you again and try to correct the problem as soon as possible.

    Good day!

    Hope this information helps.

  • Simple query to find the difference between 2 numbers in one column to another column

    Hello

    I would like to know the difference between 2 numbers in same column corresponding to a condition of another column. How do that?

    For example: say I have a table with 3 columns A, B and C.

    A > Varchar2

    B > Varchar2

    C > number

    A B C
    AD1
    BC2
    CB3
    DA4

    I want something like 'column value corresponding C min min (col B) result = (col A) - value of the corresponding C column (number)' without having to write 2 select statements. How do I do that?

    Thanks in advance

    aBBy007



    Notes on the system:

    2-node 11.2.0.3.4 GI/RDBMS running on RHEL5.

    Hello

    It is not very similar to your original question.  It would be better if you asked what you really want in your first post, rather than making people to time writing solutions you want not and can not use waste.  Once you see an answer to this question, will you change the question again?

    Here's a way to do what you asked:

    WITH got_lasts AS

    (

    SELECT val.thread #.

    , MAX (val.sequence #) AS last_standby_seq_received

    MAX (CASE

    WHEN val.applied = "YES".

    THEN val.sequence #.

    END

    ) AS last_standby_seq_applied

    V $ archived_log val

    Join v$ database vdb WE val.resetlogs_change #.

    = vdb.resetlogs_change #.

    GROUP BY thread #.

    )

    SELECT thread #.

    last_standby_seq_received

    last_standby_seq_applied

    last_standby_seq_received

    -last_standby_seq_applied AS total_lag

    OF got_lasts

    ORDER BY thread #.

    ;

  • Where can I find the 'Ask buy opinion' when using family shares if I Don t trust the immediatily?

    Find the notice "To buy" in the sharing of the family

    Welcome to the Apple community.

    You should see it in your notification Center sliding down from the top of the screen.

Maybe you are looking for