Number Total between Gap

Is there a way to draw a total number between the gaps?

For example:

COL_A
----------
1
2
3
6
10
12
13
14



If there is a gap, I would like to know the number who are starting out and the difference:
START END DIFFERENCE
3-6-2
6-10-3
10-12-1

Thanks for any guidance or the sense of what I might try. I've seen a few examples on how to get all the missing numbers, but something like that.

Hello

You can do it with the analytical function of LEAD (or GAL):

WITH  got_next_a  AS
(
     SELECT  col_a
     ,     LEAD (col_a) OVER (ORDER BY col_a)     AS next_a
     FROM     table_x
)
SELECT       col_a
,       next_a
,       (next_a - col_a) - 1     AS difference
FROM       got_next_a
WHERE       next_a     != col_a + 1
ORDER BY  col_a;

Like all analytical functions, LEAD is calculated after the clause WHERE is applied.
If you want to use the value in a WHERE clause (as we do here). then a subquery (as got_next_a) is necessary.

Tags: Database

Similar Questions

  • When count sum ID number total < 300

    Afternoon Folks,

    I was wondering if someone could help me with a query of code?

    I'm counting the number of Packs of Service where the total payment of the amount for each separate sp_id is less than 300 pounds and also more than 300 pounds.

    This is the code I have so far:

    Select the specialty
    count (distinct sp_id) "Service Packs",
    Sum (payment_total) "Total paid £»,
    round (sum (payment_total) / count (distinct sp_id), 0) 'average spend by MS.
    of a3_fact_sms_service_inv
    where specialized ("podiatry", "Podiatry")
    and service_date between '01 Jan 11' and 31 Dec 11'
    Specialty group

    This is the table that I want it to look

    SPECIALTY Service Packs Total paid £ average spend by SP * < 300 * > 300 *.
    Podiatry 129 25682,26 199 * 107 * 22 *.
    Podiatry 622 206651,08 332 * 403 * 219 *.

    I'm currently running application 10 g

    Concerning
    Farming :)

    First of all, ' 01 Jan 11' is not a date, but rather a string. Use literals date (or at least to_date):

    with t as (
               select  specialty,
                       sp_id,
                       sum(payment_total) sp_id_total
                 from  a3_fact_sms_service_inv
                 where specialty in ('Chiropody','Podiatry')
                   and service_date between date '2011-01-01' and date '2011-12-31'
                 group by specialty,
                          sp_id
              )
    select  specialty,
            count(sp_id) "Service Packs",
            sum(sp_id_total) "Total Paid £",
            round(sum(sp_id_total) / count(sp_id)) "Average Spend per SP",
            count(case when sp_id_total < 300 then 1 end) "Service Packs Less £300",
            count(case when sp_id_total = 300 then 1 end) "Service Packs Equal £300",
            count(case when sp_id_total > 300 then 1 end) "Service Packs Greater £300"
      from  t
      group by specialty
    /
    

    SY.

  • PIX-limit connections embrionic &amp; total between INSIDE and OUTSIDE.

    It is medium possible and straight forward to limit the number of connections embrionic and total if a PIX from the outside to the inside by using the parms in the NAT and STATIC commands.

    This list is possible to limit the embrionic connections and total from one host to the PIX INSIDE make the connections to the outside?

    Follow these steps exactly the same way. Assume that the host inside is 10.1.1.1.

    Keep in mind that if you have the following:

    public static 50.50.50.50 (Interior, exterior) 10.1.1.1 netmask 255.255.255.255 1000 25

    Then, it creates a static for the inside host 10.1.1.1 and will limit connections to or FROM this host to 1000.

    If you do not want to chew a static (and an external address) for this inside the host, you can do something like the following:

    Global interface 20 (external)

    NAT (inside) 20 10.1.1.1 1000 25

    and outbound connections to this host will be PAT had the address of the external interface, but will be limited to 1000 connections or semi-open 25.

  • How do I see the number Total of Hits looking for Windows 7?

    The Windows XP search companion always informed the user the number of visits ("found 50 to date"), even in real time. In Windows 7, it is a confidential information jealously guarded, or so it seems.

    TIA,

    -RFH

    Hi Ray Cambridge,.

    If you want to know the number of files found after research all you have to do is you have to select all the files by pressing on Ctrl + A so that all the files will choose and then on the lower left corner, it will show the total number of files count.

    Hope this information is helpful and let us know if you need more assistance. We will be happy to help.

  • Number of table gap

    RDBMS Version: 11.2.0.4

    OS: RHEL 6.6

    Total number of tables in this schema is 282. But, why East-County of user_segments.segment_type = 'TABLE' watch only 119? What is there such a difference?

    SQL > select count (*) from user_Tables;

    COUNT (*)

    ----------

    282

    SQL > select count (*) from user_objects where type_objet = "TABLE";

    COUNT (*)

    ----------

    282

    SQL >

    SQL > select count (*) from WHERE user_segments where segment_type = 'TABLE ';

    COUNT (*)

    ----------

    119

    -Various types of objects in this diagram and the number

    SQL > select segment_type, count (*) group WHERE user_segments by order segment_type of count (*) desc;

    SEGMENT_TYPE COUNT (*)

    ------------------ ----------

    INDEX 158

    TABLE                     119

    66 INDEX PARTITION

    LOBSEGMENT 33

    33 TABLE PARTITION

    LOBINDEX 33

    LOB PARTITION 33

    7 selected lines.

    Empty tables with delayed segment usually have a row in user_segments WHERE

  • Obligation to print page numbers: number/Total reset Invoic to the Page level

    Hi all

    We have a requirement to print as page numbers below:

    4597 1/4. In this example, the number of trx is 4597 and it has 4 pages and the current page is number 1. To page 2, he printed at 4597 2/4. Page 3, to printed 4597 3/4 page 4, she to printed 4597 4/4.

    We are facing questions during reset the count at the level of the page as if we then head charge page numbers are displayed as: 2/1.

    Can you please help how we can solve this problem in the XML reports.

    Kind regards
    Suresh Reddy

    Do you use

    Concerning
    Charlotte

  • Does Oracle 10g - Record Count/Total number of records.

    Hello, I'm looking to display the current records of number / total Records at the bottom left of a custom form. Please see below, made me know how this is done. Enjoy it!

    record_count.jpg

    Thanks, Naveen.

    Your question is unclear.  Forms already did what you mentioned and appears as such in the image you downloaded.  If you don't see it in a particular form, open the form in the report generator and check at the level of the 'form', property 'The Console window' is not NULL and properly reflects the name of the appropriate window.  A NULL value prevents the message bar appears.

  • No sales the total number of fotografías en vidéoconférence del ano (No. leaves the total number of photos in the year of the record)

    Hola: Desde ayer Ligthroom no CC no marca el number total of fotografías en the vidéoconférence main del ano, en los meses TR. ¿pueden help me? (Hello: since yesterday Lightroom CC didn't mark not the total number of photos in the main folder of the year, if in the months. can you help me?)

    On the main menu, click library, click {view the Photos in subfolders} to turn.

  • JavaScript anomaly on the number of days between two dates

    Use ApEx 4.0, I found an anomaly in a javascript code that calculates the number of days between two dates, the current_date and the past_date. If the past and present is the or before March 10, 2013, and the current_date lies between 10 March 2013 and November 3, 2013, the number of days will be from 1 day to less than the actual number. Between November 3, 2013 and on 4 November 2013, the increments of number by 2, then the count will be accurate from this date forward.

    Here are some examples:

    March 10, 2013 = 69 days of December 31, 2012
    March 11, 2013 = 69 days of December 31, 2012
    March 12, 2013 = 70 days of December 31, 2012

    November 3, 2013 = 306 days in December 31, 2012
    November 4, 2013 = 308 days in December 31, 2012

    11 March should be 70 and 12 March should be 71. November 3 is 307 and 4 November corrects the number of fake, which began March 11.

    Change the past_date to March 10, 2013 produces the following:

    March 10, 2013 = 0 days of March 10, 2013
    March 11, 2013 = 0 days of March 10, 2013
    March 12, 2013 = 1 days of March 10, 2013

    But change the past_date to 11 March 2013, product of the correct numbers:

    March 11, 2013 = 0 days of March 11, 2013
    March 12, 2013 = 1 days of March 11, 2013
    March 13, 2013 = 2 days of March 11, 2013

    I would certainly all help to determine the cause of this anomaly. Here's the javascript code:

    var w1 = ($v ("P48_PAST_DATE"));
    W1 = (w1.toString ());
    vmon var = (w1.substr (3.3));
    vyr var = (w1.substr (7));
    var r = (vyr.length);
    If (r == 2)
    vyr. = (parseFloat (vyr) + 2000);
    vday var = (w1.substr (0.2));
    var y = (vmon.concat ("", vday, ",", vyr));
    y = Date.parse (y);

    var w2 = ($v ("P48_CURRENT_DATE"));
    var vmon2 = (w2.substr (3.3));
    var vyr2 = (w2.substr (7));
    var vday2 = (w2.substr (0.2));
    var x = (vmon2.concat ("", vday2, ",", vyr2));
    x = Date.parse (x);

    var numdays = (x - y);
    numdays = (Math.floor(numdays / 86400000));
    $s ("P48_NUMBEROFDAYS", numdays);

    Did you google for something like "javascript number of days between two dates. I think you will find the explanation to this observation:

    This method does not work correctly if there is an advanced economies jump between the two dates.

    There are examples available to calculate the difference between two dates.

  • I think someone changed my MacBook Air charger, is it possible to identify one that came with the computer? It has a serial number attached. Please help, thanks!

    I think someone changed my MacBook Air charger, is it possible to identify the one supplied with the original computer?, if it has no serial number connected to the computer?, thank you!

    There is no serial number match between the computer and the charger. All MBA models came with a 45W charger and there is no danger in using a higher power charger.

  • total impressions on a 4500th want all-in-one?

    How do you determine the total impressions on a 4500th want all-in-one?

    Hello

    Click on the button down until the Tools option appears highlighted, and then click OK.

    Scrool up to the State of the printer report amd click OK.

    The printer Status Report list the number Total of Pages in the section printing information.

  • calculate the percentage of error in the table with a reference number

    Hello

    I am able to make the mistake of column 0, table...

    How I would be writing the code for the column 1, 2, as well as the n column?

    You really do need to learn more about arrays and scalars. You use tables 1 d as the scalars and arrays in tables 1 d 2D. Transpose two operations in a row is a NOP, why do it?

    Do not have the same code in all cases a case structure. Everything is the same thing belongs outside. Only one number differs between business and it's the only thing that belongs inside picture).

    Do not bury terminals inside the loops and other structures. They belong to the toplevel chart background.

    Here is a quick sketch.

  • BlackBerry Smartphones Total/free file is off the reserve (22 M / 83M bytes free)

    When I look in Options/status and click the menu button to check the sizes of database, I see 'Bank of content' is almost 3800 bytes.  How can I see which programs specifically eat to the top of my memory?

    You are in great shape! I only have Google Maps, Jtetris and installed Opera Mini and I'm 23 MB to my free file )

    Usually if you toll free number is between 5 to 10 MB, you should be worried about.

  • Total count repeated in each rtf page

    Hi all


    Here is the example of rtf code. Everything works fine, except the number Total is to repeat on each page. We want to show that ultimately not in every page. Any suggestions!


    Thank you


    Sushil



    <? for-each-group@section:G_1;. / REGION? > <? sorting: current-group () / REGION; ' ascending '; data-type = "text"? >

    Region: <? REGION of? >

    State: <? STATE? >

    <? start: body? > <? for-each-group@section:current-group();. / STATE? > <? sorting: current-group () / STATE; ' ascending '; data-type = "text"? >

    <? start: body? > <? for-each - group:current-group();. / STATUS_NAME? > <? sorting: current-group () / STATUS_NAME; ' ascending '; data-type = "text"? >

    EMP ID

    CITY

    COUNTY OF

    F EMP_ID

    CITY_NAME

    COUNTY_NAME E

    <? end for each group -? >

    <? : slim body? >

    <? end for each group -? >

    <? : slim body? >

    <? end for each group -? >

    Total: County EMP_ID                                                                                                                                              

    Since you are using for-each@section - County appeared on all pages.

    You can use the last page only content logical and restrict total to appear on last page only.

    Syntax:

    See the user guide on the use of the Designer's Guide report Oracle Fusion Middleware for Oracle Business Intelligence Publisher

  • How to caluclate tat between two dates of a timestamp field

    Hello
    could help to caluclate days between two dates and unique timestamp filed with this
    query
    Select * from m_activity_transaction where actn_opp_id in)
    Select actn_opp_id in the m_activity_transaction where ACTN_ACTV_ID = 218
    Actn_opp_id group
    view count (*) > 1) and ACTN_ACTV_ID = 218
    order of actn_performed_on
    IAM get output is

    ACTN_ID ACTN_OPP_ID ACTN_PERFORMED_ON
    319415 95831 JANUARY 27, 12 AM 11.06.20.000000
    315249 95831 8 FEBRUARY 12 05.32.54.000000 PM
    301927 103509 20 DECEMBER 11 04.01.43.000000 PM
    301458 103509 19 DECEMBER 11 04.51.03.000000 PM
    294841 115840 10 JANUARY 12 03.20.12.000000 PM
    312062 115840 11 JANUARY 12 05.17.06.000000 PM

    Normand to caluclate number days between two dates like January 27, 12 AM 11.06.20.000000 and I 05.32.54.000000 8 February 12 PM where actn_id is unique AND ACTN_OPP_ID IS NOT UNIQUE.
    Thanks in advance,
    VVR.

    In this way.

    with data as
    (
    select 315249 a, 95831 b, to_date('27-JAN-12 11.06.20 AM', 'DD-MON-RR HH.MI.SS AM') dt from dual union all
    select 319415, 95831, to_date('08-FEB-12 05.32.54 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 301927, 103509 , to_date('20-DEC-11 04.51.03 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 301458 , 103509 , to_date('19-DEC-11 04.01.43 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363810 , 144656 , to_date('27-JUN-12 12.43.28 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363500 , 144656 , to_date('26-JUN-12 11.41.50 AM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363354 , 144656 , to_date('25-JUN-13 12.41.13 PM', 'DD-MON-RR HH.MI.SS AM') from dual
    )
    select a, b, diff_in_days
      from (
            select a, b, trunc(dt - lag(dt) over (partition by b order by dt, a)) diff_in_days
              from data
           ) tab
     where tab.diff_in_days is not null;
    
    A                      B                      DIFF_IN_DAYS
    ---------------------- ---------------------- ----------------------
    319415                 95831                  12
    301927                 103509                 1
    363810                 144656                 1
    363354                 144656                 362
    

Maybe you are looking for