Help with Update SQL

Hi,
I have the following SQL and I need your help.
declare
i_howMany number;
begin
i_howMany := ?;
update NumberRange
set lastNumberAssigned = lastNumberAssigned + i_howMany
where rangeType = ? and lastNumberAssigned < maxNumber
returning (lastNumberAssigned - i_howMany + 1), lastNumberAssigned into ?, ?;
end;
Is it possible to refactor the above SQL to return a ResultSet with 2 Number fields, i.e. fromNumber and toNumber?
Regards,
Judyee

Hi,
The table NumberRange has the following fields and data.
This table is used to store the number sequences for Booking ID, Invoice ID, etc.
Note that I can't use Oracle Sequences as the values are maintained by external parties, and a change to Oracle Sequences would mean a re-write of the application functionality.
NumberRange
rangeType maxNumber lastNumberAssigned
'Booking' 20000 500
'Invoice' 10000 10
There are 2 input parameters:
- i_howMany - this is used to get a range of numbers (i.e. from & to numbers) from NumberRange
- rangeType - this is used to identify the rangeType, e.g. Booking.
There are 2 output fields that contain the assigned number range (which I want to be returned in a ResultSet)
- fromNumber
- toNumber
For example:
1st parameter (i_howMany) = 5
2nd parameter (rangeType) = 'Booking'
Output fields (based on the above example) will be:
- fromNumber = 501
- toNumber = 505
I just want the 2 output fields to be in a ResultSet as the calling program will be expecting the result in a ResultSet.
Regards,
Judee

Similar Messages

  • Help with update SQL query

    Hi,I want to update the city_code with city_new_code but want to update the data before the first hyphen of city_code.
    create table #city (city_code char(10), city_code char(2), city_new_code char(10))
    insert into #city values ('1989_DEL_J1_200','2','2000')
    insert into #city values ('1789_DEL_K1_300','2','3000')
    insert into #city values ('1999_DEL_J1_400','2','5000')
    update #city set city_code........
    /* Need Required Output*/
    city_code         city_code  city_new_code
    2000_DEL_J1_200   2              2000
    3000_DEL_K1_300  2               3000
    5000_DEL_J1_400   2              5000

    create table #city (city_code varchar(15), city_code2 char(2), city_new_code varchar(4))
    insert into #city values ('1989_DEL_J1_200','2','2000')
    insert into #city values ('1789_DEL_K1_300','2','3000')
    insert into #city values ('1999_DEL_J1_400','2','5000')
    --update #city set city_code........
    update #city
    Set city_code=stuff(city_code,1,4,city_new_code)
    Select city_code,city_code2,city_new_code from #city
    drop table #city

  • MAC OS 10.6.8 Using Safari 5.1 Needing Help With Updating Adobe Flash

    Hello-
    Recently Adobe Flash installed an icon in my System Preferences and when I click the icon there are several tabs.  One allows updates to check automatically.  It says it will install the latest version of Flash without having to remove the previous version, but I have never been told that a newer version is available unless I clcik "check now."  although "Check for updates automatically" is checked, I do not know where it tells me a newer version is available.  Also, there has been 5 "newer versions" available since this icon was installed in System Prefeences, I have only found out about the newer versions when I clicked "Check Now."  If I read that with this new way to install the latest Mac version of Flash does not require me to uninstall the previous version of Flash how do I install the most recent version of Flash?  Does it come in an email?
    Since it is not telling me that there is a more recent version of Flash unless I click "Check Now" should I still do it the way I used to install the latest version of flash?  (The way before this icon was added to System Preferences)?
    I would appreciate help with updating Flash to the most recent version.  I used to uninstall the older version, restart the browser and download the most recent version and install it.  It always worked find but this was before there was an Adobe icon in my system Preferences.

    Hello,
    The way you used to do this (uninstall, restart the browser, etc.) is still definitely valid and probably the "safest" way to get a new version installed.  Uninstalling shouldn't be required, but it definitely doesn't hurt.  If you feel comfortable doing it the old way, please feel free to continue using that process.
    As for notifications, this is a bit trickier, but in general you should be notified within 30 days (or so) after a new player is released.  This usually occurs when the browser loads swf content.  Clicking the button will, like you mention, immediately check.  Another alternative to finding out when a new player is released is to subscribe to our Flash Player Releases feed.
    Is there a way to be automatically notified when a new Flash Runtime release is made?
    Thanks,
    Chris

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Help with updates for CS6

    I need help installing latest updates for CS6.  I have Win 7 and have tried updating from the Help - Updates menu.  The error is:  U43M1D207.

    Thanks for your response.  I am in the United States in So. Arizona.
    Date: Fri, 5 Oct 2012 12:21:45 -0600
    From: [email protected]
    To: [email protected]
    Subject: Help with updates for CS6
    Re: Help with updates for CS6 created by Jeff A Wright in Downloading, Installing, Setting Up - View the full discussion
    Crunkle1 you are welcome to work directly with our support team for guided assistance.  If you go to http://www.adobe.com/ and select Help and Contact Us you should be given the option to contact our support team via telephone.  Which country/region are you in?
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/4752605#4752605
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4752605#4752605
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4752605#4752605. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Downloading, Installing, Setting Up by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • HT201541 I need help with updating my browser.

    I need help with updating my browser.  Its telling me that Safari is outdated.

    That is a very old version belonging to Snow Leopard. I take it you are not actually running Yosemite.
    Upgrading to Yosemite
    You can upgrade to Yosemite from Lion or directly from Snow Leopard. Yosemite can be downloaded from the Mac App Store for FREE.
    Upgrading to Yosemite
    To upgrade to Yosemite you must have Snow Leopard 10.6.8 or Lion installed. Download Yosemite from the App Store. Sign in using your Apple ID. Yosemite is free. The file is quite large, over 5 GBs, so allow some time to download. It would be preferable to use Ethernet because it is nearly four times faster than wireless.
        OS X Mavericks/Yosemite- System Requirements
          Macs that can be upgraded to OS X Yosemite
             1. iMac (Mid 2007 or newer) - Model Identifier 7,1 or later
             2. MacBook (Late 2008 Aluminum, or Early 2009 or newer) - Model Identifier 5,1 or later
             3. MacBook Pro (Mid/Late 2007 or newer) - Model Identifier 3,1 or later
             4. MacBook Air (Late 2008 or newer) - Model Identifier 2,1 or later
             5. Mac mini (Early 2009 or newer) - Model Identifier 3,1 or later
             6. Mac Pro (Early 2008 or newer) - Model Identifier 3,1 or later
             7. Xserve (Early 2009) - Model Identifier 3,1 or later
    To find the model identifier open System Profiler in the Utilities folder. It's displayed in the panel on the right.
         Are my applications compatible?
             See App Compatibility Table - RoaringApps.
    Upgrading to Lion
    If your computer does not meet the requirements to install Mavericks, it may still meet the requirements to install Lion.
    You can purchase Lion at the Online Apple Store. The cost is $19.99 (as it was before) plus tax.  It's a download. You will get an email containing a redemption code that you then use at the Mac App Store to download Lion. Save a copy of that installer to your Downloads folder because the installer deletes itself at the end of the installation.
         Lion System Requirements
           1. Mac computer with an Intel Core 2 Duo, Core i3, Core i5, Core i7,
               or Xeon processor
           2. 2GB of memory
           3. OS X v10.6.6 or later (v10.6.8 recommended)
           4. 7GB of available space
           5. Some features require an Apple ID; terms apply.

  • Help with updates - The software change returned error code 0x87D00215(-2016411115).

    I have rolled out bunch of updates across few hundred workstation systems.
    Few of the desktops have failed to install SOME of the updates and just can't get my head around as to why?
    Looking at one of the workstations, I can see 5 updates are pending download at 0%.
    Some of these fail after a while and with in Software Centre, I can see 'Help with updates - The software change returned error code 0x87D00215(-2016411115).'. Not exactly sure what this means, but I have tried clearing the cache and
    rebooting the workstations few times.
    (I have also tried to use Windows Update and install one of these manually, which worked.)

    Investigating this further, I have found the following in CAS.log:
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {ED6E9E5C-E806-43CA-9F93-49AC72D1DEAD} for content 53bf87a2-bedf-4def-b0ec-9637613c3429.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting locations synchronously for content 99ddb078-b780-4605-8fac-9607fe56450d.1 with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    The number of discovered DPs(including Branch DP and Multicast) is 1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Calling back with the following distribution points ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Distribution Point='http://DPSERVER.com/SMS_DP_SMSPKG$/99ddb078-b780-4605-8fac-9607fe56450d', Locality='LOCAL' ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting content 99ddb078-b780-4605-8fac-9607fe56450d.1, size(KB) 0, under context System with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {67B7E59B-A386-4EA8-BF39-2EB64B108A6C} for content 99ddb078-b780-4605-8fac-9607fe56450d.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting locations synchronously for content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1 with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    The number of discovered DPs(including Branch DP and Multicast) is 1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Calling back with the following distribution points ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Distribution Point='http://DPSERVER.com/SMS_DP_SMSPKG$/61d33de7-9582-41e3-82fc-3e0f970b60f3', Locality='LOCAL' ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Requesting content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1, size(KB) 0, under context System with priority Foreground ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    ICcmContentTransferManager::ModifyJobPriority failed with error 0x87d00215 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    No need to change timeout settings ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)
    Successfully created download request {12E48136-B545-4C42-9745-9FF97CE38D52} for content 61d33de7-9582-41e3-82fc-3e0f970b60f3.1 ContentAccess 01/06/2013 17:19:24 3316 (0x0CF4)

  • Help with Update task

    Hi friends,
    In the below am trying to update a custom table using a call function in update task. I dont see the table getting updated can someone take a look at it and let me knw what the problem is? I have the commit work statement and also marked the function module as an update one in the attribute. Please help me . Thanks in advance! kathy
    *&  Include           ZINBOUND_TEST
    Report: ZINBOUND_TEST.
    DATA: l_dest     TYPE REF TO if_bgrfc_destination_inbound,
          l_unit     TYPE REF TO if_trfc_unit_inbound,
          l_inb_dest TYPE bgrfc_main_i_dst,
          lv_matid TYPE /sapapo/matid,
          lv_matnr TYPE /sapapo/matnr,
          lv_maktx type /SAPAPO/MAKTX,
          lv_langu  TYPE LANGU.
    data: lt_product type  STANDARD TABLE OF ZUPDATE,
          ls_product type ZUPDATE.
    lv_matid = '123'.
    lv_langu = 'E'.
    lv_maktx = 'Materia1'.
    CALL FUNCTION 'Z_TEST' IN UPDATE TASK
      EXPORTING
        iv_matid = lv_matid
        iv_maktx = lv_maktx
        iv_langu = lv_langu .
    COMMIT WORK.
    select * from zupdate into corresponding fields OF TABLE lt_product.
    if sy-subrc <> 0.
      write 'no records added'.
    else.
      loop at lt_product into ls_product.
        write: / ls_product-MATID,
                 ls_product-MAKTX.
      endloop.
    endif.
    FUNCTION Z_TEST.
    *"*"Update Function Module:
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(IV_MATID) TYPE  /SAPAPO/MATID
    *"     VALUE(IV_MAKTX) TYPE  /SAPAPO/MAKTX
    *"     VALUE(IV_LANGU) TYPE  LANGU
    data: itab type standard table of zupdate,
    wa_itab type zupdate.
    wa_itab-matid = iv_matid.
    wa_itab-maktx = iv_maktx.
    wa_itab-langu = iv_langu.
    append wa_itab to itab.
    update zupdate from table itab .
    ENDFUNCTION.
    Edited by: ka reddy on Sep 24, 2009 4:14 PM
    Edited by: ka reddy on Sep 24, 2009 4:15 PM
    Edited by: ka reddy on Sep 24, 2009 4:16 PM
    Edited by: ka reddy on Sep 24, 2009 4:17 PM
    Edited by: ka reddy on Sep 24, 2009 4:21 PM

    Hey Naimesh thanks for the reply. yeah i read that document way before and i started taking a stab at implementing it.
    I started with update task to see how it behaves and then wanted to go with BGRFC tats when i had the update issue.
    Now that am done with update i want to implement BGRFC.
    I have modified the earlier prgm...Can you give me some ideas how to extend this? Thanks!
    *&  Include           ZBGRFC_INBOUND_TEST
    Report: ZBGRFC_INBOUND_TEST.
    DATA: l_dest     TYPE REF TO if_bgrfc_destination_inbound,
          l_unit     TYPE REF TO if_trfc_unit_inbound,
          l_inb_dest TYPE bgrfc_main_i_dst,
          lv_matid TYPE /sapapo/matid,
          lv_matnr TYPE /sapapo/matnr,
          lv_maktx type /SAPAPO/MAKTX,
          lv_matid1 TYPE /sapapo/matid,
          lv_matnr1 TYPE /sapapo/matnr,
          lv_maktx1 type /SAPAPO/MAKTX,
          lv_langu1  TYPE LANGU,
          lv_langu  TYPE LANGU.
    data: lt_product type  STANDARD TABLE OF ZUPDATE,
          ls_product type ZUPDATE.
    lv_matid = '125'.
    lv_langu = 'E'.
    lv_maktx = 'Materia3'.
    **--Get the inbound destination for BGRFC.
      IF l_inb_dest IS INITIAL.
          SELECT SINGLE * FROM bgrfc_main_i_dst INTO l_inb_dest.
        ENDIF.
        l_dest = cl_bgrfc_destination_inbound=>create( l_inb_dest-destination ).
        l_unit = l_dest->create_trfc_unit( ).
    CALL FUNCTION 'Z_TEST' IN BACKGROUND UNIT l_unit
      EXPORTING
        iv_matid = lv_matid
        iv_maktx = lv_maktx
        iv_langu = lv_langu .
    select * from zupdate into corresponding fields OF TABLE lt_product.
    if sy-subrc <> 0.
      write 'no records added'.
    else.
      loop at lt_product into ls_product.
        write: / ls_product-MATID,
                 ls_product-MAKTX.
      endloop.
    endif.
    Edited by: ka reddy on Sep 24, 2009 5:16 PM

  • Help with:   java.sql.SQLIntegrityConstraintViolationException

    Hi, guys
    I need help with the following exception: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL090403155751200' defined on 'BOOK_ORDER'.
    the things is my primary key is unique, so i checked the indexes and i found that i have two 'SQL090403155751200' indexes.
    I would like to know:
    1. can i delete the index without causing further database problems
    2. what causes this problem and how can i avoid it.
    By the way im using netbeans 6.5 and derby database

    rizza_99 wrote:
    I would like to know:
    1. can i delete the index without causing further database problems
    2. what causes this problem and how can i avoid it.
    By understanding what the application/system is supposed to be doing and the correctly creating indexes on the database that reflect the business needs.
    Once you do that then the nature of the indexes that are needed are obvious.
    You certainly don't delete indexes without that understanding however.

  • Help with Updates

    My son has a Droid Inc2 and has had multiple problems with updates. They always happen overnight and he gets a message telling him to do a battery pull to avoid further messages regarding the update. Each time we eventually have to do a hard reset so that we can restore the service to the phone. This has been happening for quite sometime now starting back in early August.
    The current software running is 3.02.605.1. My wife messaged a VZW Support Rep on Twitter about it and was told it was an old software version and to keep trying to pull the update. We have stopped trying since having to do a reset this weekend. This is really aggravating and I need to know what we should do. Right now if you check for software update it acts like it's checking but then does nothing more. Then in a couple days the phone will try to update overnight.
    Someone please tell me what needs to be done. I have looked thru the oter posts and couldn't find what I needed and got tired of looking at all the pages of posts regarding the updates.
    Thx!

    AntonioC_VZW wrote:
    Hi 2tonpickup,
    I understand your concerns regarding your son's phone. We also value your time and have different processes in place to troubleshoot any issues with your phones. Please keep in mind that this is a peer to peer forum and while our Social Media Team monitors these forums the best way to get assistance troubleshooting a device is to call us at 800-922-0204 from a different phone and have the faulty device fully charged and available when calling.
    Your device includes a one year manufacturer's warranty and we'll be happy to replace it with a Certified Like New unit of the same model if we are unable to resolve your concerns and phone is under warranty. Please visit this LINK for replacement process details.
    To the original poster: Please keep in mind that the Verizon employees are moderators, meaning that they mostly make sure we abide by the rules and regulations of the forums. While they do chime in occationally to help, your best bet is really to call tech support first or to go into a Verizon store.

  • Help with Update failure please

    I have Adobe Photoshop CC running on win 7 64 bit. When doing the latest batch of updates one keeps failing with the error message "Adobe CSXS Infrastructure 4 Installation Failed Error Code U44M1P7" Can anyone help with this?

    Thanks Eshant
    I had since  been researching this on the web and it seems it is a very
    common fault which has not always been fixed by the full re-install
    advocated by Adobe in the link you kindly provided. I therefore decided
    to keep trying for a couple of days before resorting to such a drastic
    solution.
    After several failures to get CSXS Infrastructure 4 to install, both via
    the CC Desktop App and from the "Help" menu within Photoshop CC, I had
    one more try this morning and this time it seems to have installed
    without a hitch. I have no idea why, as I have made no system changes,
    but for now I do seem to have solved the problem as my installation of
    Photoshop CC is now reporting that it is fully up to date.
    Thanks for your response.
    Pixellated

  • Help with updating the grid(CONNECT 4)

    Hi, this a small portion of my connect 4 game program. I have a problem with updating the grid. During the game, whenever I enter a column number for the first time, the program works properly. But when i try to give the same column for the second time, the chip falls in the same row instead of going to the second row. Can anybody help me write the method that will do this.
    This is the method that switches the chip's value(By the way discard the variable 'turn' because that works properly, it is used in another method):
        //Method 2: Updates the matrix
        public static void UpdateMatrix (char location, char turn)
            c.println (location);
            switch (location)
                case '1':
                    matrix [5] [0] = turn;
                    break;
                case '2':
                    matrix [5] [1] = turn;
                    break;
                case '3':
                    matrix [5] [2] = turn;
                    break;
                case '4':
                    matrix [5] [3] = turn;
                    break;
                case '5':
                    matrix [5] [4] = turn;
                    break;
                case '6':
                    matrix [5] [5] = turn;
                    break;
                case '7':
                    matrix [5] [6] = turn;
                    break;
        } //End Method 2Can anybody describe me how to write a method or write a method that will tell the computer to assign the chip to the next row. You an edit my method if u want to. THANX A LOT!!!

    HERE IS THE METHODS SO FAR!
        //Method 3: Checks if assigned place for the chip has a chip there already
        public static void emptyspot (int column, int row)
            for (row = 5 ; row >= 0 ; row--)
                for (column = 0 ; column <= 6 ; column++)
                    if (matrix [row] [column] == 'X' || matrix [row] [column] == 'O')
                        row--;
        }I AM GETTING AN ERROR!!! AT THE BOTTOM OF MY PROGRAM! SOMEBODY HELP!
    Message was edited by:
    Taufiq

  • Help with PL/SQl .....Sysdate-1

    Hi all ..Need help with this
    to_char(last_day(add_months(sysdate,-1)),'mm/dd/yyyy')
    Its an Oracle 10g. We use two schemas out of many for Enterprise wide DW. They have 9 base tables in one of the schemas.. We have hundreds of views from that base tables . This SQL command is against one of the view . We basically need all the applications made by customers drilled by region,area,city etc. in the last month using this command.
    Here we are using sysdate - 1 to retrieve reports for the last months data. These reports are run monthly on first business day once. But due to any problem if it runs after 3rd or 4th of the month it returns data from last months 3rd to this months 3rd which is logically wrong. Is there any solution so that whenever the report may run it has to return last months data from first of last month to last day of last month. It would be of great help if anyone gives the solution.
    Thanks
    Tom

    Tom,
    Something like this
    SELECT     ADD_MONTHS (TRUNC (SYSDATE), -1)
             - TO_NUMBER (TO_CHAR (ADD_MONTHS (TRUNC (SYSDATE), -1), 'DD'))
             + 1
                first_date,
             LAST_DAY (ADD_MONTHS (TRUNC (SYSDATE), -1)) last_date
      FROM   DUAL;Regards

  • Anybody can help with this SQL?

    The table is simple, only 2 columns:
    create table personpay(
    id integer primary key,
    pay number(8,2) not null);
    So the original talbe looks like this:
    ID PAY
    1 800
    2 400
    3 1200
    4 500
    5 600
    6 1900
    The requirement is to use one single query(no pl/sql) to show something lile the following, in other words, for each ID, the pay is the sum of all before itself and itself. So the query result looks like this:
    ID PAY
    1 800
    2 1200
    3 2400
    4 2900
    5 3500
    6 5400
    Again, just use one sql. No pl/sql. Anybody can help with this? I really appreciate that.
    thanks,

    Eh, people are so "analytically minded" that can't even notice a simple join?
    Counting Ordered Rows
    Let’s start with a basic counting problem. Suppose we are given a list of integers, for example:
    x
    2
    3
    4
    6
    9
    and want to enumerate all of them sequentially like this:
    x      #
    2      1
    3      2
    4      3
    6      4
    9      5
    Enumerating rows in the increasing order is the same as counting how many rows precede a given row.
    SQL enjoys success unparalleled by any rival query language. Not the last reason for such popularity might be credited to its proximity to English . Let examine the informal idea
    Enumerating rows in increasing order is counting how many rows precede a given row.
    carefully. Perhaps the most important is that we referred to the rows in the source table twice: first, to a given row, second, to a preceding row. Therefore, we need to join our number list with itself (fig 1.1).
    Cartesian Product
    Surprisingly, not many basic SQL tutorials, which are so abundant on the web today, mention Cartesian product. Cartesian product is a join operator with no join condition
    select A.*, B.* from A, B
    Figure 1.1: Cartesian product of the set A = {2,3,4,6,9} by itself. Counting all the elements x that are no greater than y produces the sequence number of y in the set A.
    Carrying over this idea into formal SQL query is straightforward. As it is our first query in this book, let’s do it step by step. The Cartesian product itself is
    select t.x x, tt.x y
    from T t, T tt
    Next, the triangle area below the main diagonal is
    select t.x x, tt.x y
    from T t, T tt
    where tt.x <= t.x
    Finally, we need only one column – t.x – which we group the previous result by and count
    select t.x, count(*) seqNum
    from T t, T tt
    where tt.x <= t.x
    group by t.x
    What if we modify the problem slightly and ask for a list of pairs where each number is coupled with its predecessor?
    x      predecessor
    2      
    3      2
    4      3
    6      4
    9      6
    Let me provide a typical mathematician’s answer, first -- it is remarkable in a certain way. Given that we already know how to number list elements successively, it might be tempted to reduce the current problem to the previous one:
    Enumerate all the numbers in the increasing order and match each sequence number seq# with predecessor seq#-1. Next!
    This attitude is, undoubtedly, the most economical way of thinking, although not necessarily producing the most efficient SQL. Therefore, let’s revisit our original approach, as illustrated on fig 1.2.
    Figure 1.2: Cartesian product of the set A = {2,3,4,6,9} by itself. The predecessor of y is the maximal number in a set of x that are less than y. There is no predecessor for y = 2.
    This translates into the following SQL query
    select t.x, max(tt.x) predecessor
    from T t, T tt
    where tt.x < t.x
    group by t.x
    Both solutions are expressed in standard SQL leveraging join and grouping with aggregation. Alternatively, instead of joining and grouping why don’t we calculate the count or max just in place as a correlated scalar subquery:
    select t.x,
    (select count(*) from T tt where tt.x <= t.x) seq#
    from T t
    group by t.x
    The subquery always returns a single value; this is why it is called scalar. The tt.x <= t.x predicate connects it to the outer query; this is why it is called correlated. Arguably, leveraging correlated scalar subqueries is one the most intuitive techniques to write SQL queries.
    How about counting rows that are not necessarily distinct? This is where our method breaks. It is challenging to distinguish duplicate rows by purely logical means, so that various less “pure” counting methods were devised. They all, however, require extending the SQL syntactically, which was the beginning of slipping along the ever increasing language complexity slope.
    Here is how analytic SQL extension counts rows
    select x, rank() over(order by x) seq# from T; -- first problem
    select x, lag() over(order by x) seq# from T; -- second problem
    Many people suggest that it’s not only more efficient, but more intuitive. The idea that “analytics rocks” can be challenged in many ways. The syntactic clarity has its cost: SQL programmer has to remember (or, at least, lookup) the list of analytic functions. The performance argument is not evident, since non-analytical queries are simpler construction from optimizer perspective. A shorter list of physical execution operators implies fewer query transformation rules, and less dramatic combinatorial explosion of the optimizer search space.
    It might even be argued that the syntax could be better. The partition by and order by clauses have similar functionality to the group by and order by clauses in the main query block. Yet one name was reused, and the other had been chosen to have a new name. Unlike other scalar expressions, which can be placed anywhere in SQL query where scalar values are accepted, the analytics clause lives in the scope of the select clause only. I have never been able to suppress an impression that analytic extension could be designed in more natural way.

  • I NEED SOME HELP WITH UPDATING MY IPOD TOUCH PLEASE

    i need some help with my ipod the version is 3.1.3 and every time I'm trying to update it says it can not be restored then it says unknown error so i need some help updating my ipod to version 4.2

    If you mean you're trying to update your ios go to settings/general/software update. then you should see the latest ios just tap it and it will automatically update your ipod. If you're trying to restore your ipod (as it's not quite clear in your query) try doing it through itunes instead of on the device itself

Maybe you are looking for

  • HT4314 Multiple game center accounts with on Apple ID

    We have 3 i touches at our house. My son went to add a picture to his Game Center account, and now can't get into his account, because it asks for the ID and so on. Using the Apple ID, it defaults to my game center account, and since it only asks for

  • Function module to get PR00 price

    I would like to get PR00 price(not manually changed value, but maintained in VK13, that means not the value in VBAP or KONV, but KONP I think) by inputting sales order number as import number(just like when I click analysis button as item condition v

  • Runtime problem after upgrade to 10.1.0.4

    Hello I move my database 10.1.0.4 with OWB 10.1.0.3 to another server with migrate to 10.2 db and OWB 10.1.0.4. Upgrade runtime repository script finished without errors, and runtime service launch successfully, find target schemas and upgrade it too

  • Problems while using Adobe Interactive Forms

    Hi Experts, When I execute my adobe interactive forms application that uses a BAPI to access backend I am facing the following problem: When I enter valid values and click on submit all the browser windows close without any warning or error message.

  • Huge Gaps between lines... Please Help!!!

    Hello, On various sites when i view them i get really large gaps between lines. view this screen shot: http://www.meyerfredericks.com/badbrowser.jpg How do i fix this... it does it on firefox now too since i upgraded to 3.0. So i have two browsers th