Place the missing documents in the list of records with a rank value

Hi all

I have this table:
WITH taba AS (SELECT 99 AS id,
                     '2011-08-08' AS date_ini,
                     10 AS VALUE,
                     1 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 99 AS id,
                     '2011-09-08' AS date_ini,
                     11 AS VALUE,
                     2 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 99 AS id,
                     '2011-10-08' AS date_ini,
                     10 AS VALUE,
                     4 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 999 AS id,
                     '2011-08-08' AS date_ini,
                     10 AS VALUE,
                     1 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 999 AS id,
                     '2011-09-08' AS date_ini,
                     10 AS VALUE,
                     2 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 999 AS id,
                     '2011-10-08' AS date_ini,
                     10 AS VALUE,
                     3 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 9999 AS id,
                     '2011-08-08' AS date_ini,
                     10 AS VALUE,
                     2 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 9999 AS id,
                     '2011-09-08' AS date_ini,
                     15 AS VALUE,
                     3 AS RANK
                FROM DUAL
              UNION ALL
              SELECT 9999 AS id,
                     '2011-10-08' AS date_ini,
                     10 AS VALUE,
                     4 AS RANK
                FROM DUAL)
SELECT *
  FROM taba
And I need to return the same results but with the addition of records that have no rank. For new records the VALUE must always be zero (0) and the value of DATA_INI must have the same value as the order of the records immediately following. Just like that:
99       2011-08-08     10     1
99       2011-09-08     11     2
*99       2011-10-08     0     3*
99       2011-10-08     10     4
999      2011-08-08     10     1
999      2011-09-08     10     2
999      2011-10-08     10     3
*9999     2011-08-08     0     1*
9999     2011-08-08     10     2
9999     2011-09-08     15     3
9999     2011-10-08     10     4
I can do this using a loop procedure, but I want a filter query. ;)

Thanks in advance.
Filipe Almeida

Hi, Felipe,.

So, you want multiple copies of a few lines. In other words, if a value or rnk (RANK is not a column name right) is missing in a given id you want to with the next highest rnk and the same id line repeated 2 or maybe even several times. All copies will be identical, except that rnk will have the missing numbers, and the value will be 0 on all additional copies.

A way to do that is to join your table (or something very similar to it, as in the example below) to a Meter of Table , which is a table (or a result set, in this example) counts 1, 2, 3,... up to however many copies may be required.

WITH     got_rows_needed          AS
(
     SELECT     id, date_ini, value, rnk
     ,     rnk - LAG (rnk, 1, 0) OVER ( PARTITION BY  id
                                            ORDER BY          rnk
                            )         AS rows_needed
     FROM    taba
)
,     cntr               AS
(
     SELECT     LEVEL - 1     AS n
     FROM     (
               SELECT     MAX (rows_needed)     AS max_rows_needed
               FROM     got_rows_needed
          )
     CONNECT BY     LEVEL <= max_rows_needed
)
SELECT    r.id
,       r.date_ini
,       CASE
          WHEN  c.n  = 0
          THEN  r.value
          ELSE  0
         END               AS value
,       r.rnk - c.n          AS rnk
FROM       got_rows_needed  r
JOIN       cntr             c     ON  c.n  < r.rows_needed
ORDER BY  id
,            rnk
;

By elsewhere, store date information in a VARCHAR2 column, such as date_ini, is a very bad idea. Use a DATE column.

Published by: Frank Kulash, August 8, 2012 11:02

RANK is a keyword from Oracle. (It is the name of a built-in function). If you specify your own columns of RANK, it will confuse people reading the code, and it can result in compiler errors, too.
ID is also an Oracle keyword. To be sure, you can use another name, such as grp_id, instead of id.
It is best not to name your own objects with any name of fArrondi in v$ reserrved_words.keyword.

Tags: Database

Similar Questions

  • where the list book mark with the star icon

    The list of bookmarks with a star that normally appears on the right side does not appear. Where is he

    Note that the screenshot shows you the bar menus visible.

    The button Menu bookmarks will be only visible when you hide the Menu bar you can access bookmarks from the bookmarks menu in this case.

  • Can Notes show the number of records with each folder?

    Can Notes show the number of records with each folder?

    No it can't. It would be nice tho.

  • Recorded TV causes Media Center to stop when the cursor is moved over the icon. Sometimes Blue Screen of Death. How can I remove the element from the list of recorded TV shows?

    Remember - this is a public forum so never post private information such as numbers of mail or telephone!

    Ideas:

    • You have problems with programs
    • Error messages
    • Recent changes to your computer
    • What you have already tried to solve the problem

    "This problem that I've seen before - corrupted metadata in a recorded TV file causes MC to Issac when you click on" show in the list.
    And, it is useful to know that show is the cause.  :)
    Solution: Close Media Center.  Open an Explorer window and go to C:\Users\Public\Recorded TV.  Find the offending file, and either move it to another folder (unless it is a 'protected' program, you can always watch it in Media Player), or delete.
    The file name format is: showname_network_starttime(where starttime is presented as dd_mm_yyyy_hh_mm_ss (24hours). wtv)

    HTH,
    Chris

    MS - MVP (Media Center) [If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message.] [Marking a post as answer, or relatively useful, you help others find the answer more quickly.]

  • Refresh the list of VIAccounts with PowerCli to select a newly created group

    Hi all

    I use a script that creates groups in Active Directory and connects to my server vCenter by using New-VIPermission. The trick is that it does not find the groups unless I restart the script (and so, I suppose, the connection).

    $My_Group = New-QADGroup -Name $My_AD_GroupName -SamAccountName $My_AD_GroupName -ParentContainer $My_OU -Connection $My_adConnection

    New-VIPermission -Entity $param_objects -Principal "Domain\$My_AD_GroupName" -Role ($My_Role.Name) -Propagate:($My_Role.Value) | Out-Null

    This script is going to create the group in my ad, but if you link to a new authorization in my vCenter, he'll be backNew-VIPermission Could not find VIAccount with name 'Domain\MY_GROUP_NAME'.

    When you restart the script, he will pass on the creation of group directly to the new VIPermission and properly bind to the vCenter object.

    I tried to add a waiting order, and a sleep of 5 seconds, but used to change one thing...

    How can I manage to reload and refresh the list of available groups without having to restart the vCenter connection?

    Thanks in advance!

    Well, I added the following:

    "while (!). "(() Get-VIAccount-groupe-nommer"REDOUTE_FRANCE\$ My_AD_Task_GroupName")) {Start-sleep - s 1}.

    And it works. Slow but it works

    Thanks, LucD!

  • Require a script to the list of files with sizes on all data stores in a cluster

    Hi all

    Please be gentle, im not new to Vmware, but new to powershell/powercli and need your help.

    cli power can make or y at - it tools available that will do that for me?

    I need to generate a list of all the files of the virtual machine in all stores of data available for cluster and their sizes to go with it.

    I am mainly interested in the .log files and vmdk files, but I don't mind if it lists all.

    I don't mind how his im laid out not after anything fancy just a list of output type something like

    /

    I did some research but there is nothing I have found that it will make.

    My environment is currently esx 3.0.2 with vcenter servers. (currently being upgraded to 4)

    Lots of help thanks

    Yes, it's a 'characteristic' knowledge when using PowerCLI 4u1 against a VI 3.x environment.

    There is a way to workaround, try this

    $dsImpl = Get-Cluster  | Get-VMHost | Get-Datastore | where {$_.Type -eq "VMFS"}
    $dsImpl | % {
         $ds = $_ | Get-View
         $path = ""
         $dsBrowser = Get-View $ds.Browser
         $spec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
         $spec.Details = New-Object VMware.Vim.FileQueryFlags
         $spec.Details.fileSize = $true
         $spec.Details.fileType = $true
         $vmdkQry = New-Object VMware.Vim.VmDiskFileQuery
         $spec.Query = (New-Object VMware.Vim.VmDiskFileQuery),(New-Object VMware.Vim.VmLogFileQuery)
         #Workaround for vSphere 4 fileOwner bug
         if ($dsBrowser.Client.Version -eq "Vim4") {
              $spec = [http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim4($spec)
              $spec.details.fileOwnerSpecified = $true
              $dsBrowserMoRef = [http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim4($dsBrowser.MoRef);
              $taskMoRef = $dsBrowser.Client.VimService.SearchDatastoreSubFolders_Task($dsBrowserMoRef, $path, $spec)
              $result = [http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim($dsBrowser.WaitForTask([http://VMware.Vim.VIConvert|http://VMware.Vim.VIConvert]::ToVim($taskMoRef)))
         } else {
              $taskMoRef = $dsBrowser.SearchDatastoreSubFolders_Task($path, $spec)
              $task = Get-View $taskMoRef
              while("running","queued" -contains $task.Info.State){
                   $task.UpdateViewData("Info")
              }
              $result = $task.Info.Result
         }
    
         $result | % {
              $vmName = ([regex]::matches($_.FolderPath,"\[\w*\]\s*([^/]+)"))[0].groups[1].value
              $_.File | % {
                   New-Object PSObject -Property @{
                        DSName = $ds.Name
                        VMname = $vmName
                        FileName = $_.Path
                        FileSize = $_.FileSize
                   }
              }
         }
    } | Export-Csv "C:\File-report.csv" -NoTypeInformation -UseCulture
    

    I have attached the script to avoid any problems with the hooks.

    And the regex expression is updated to account for the names of comments with whites.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • Based on the list of components with drag-/ dropEnabled = true can not coexist with other moveable components

    Hello Flexers,

    because I find it a bit difficult to describe the problem I will try that after posting the code and a screenshot:


    <s:Application
         xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx"
         width="100%" height="100%">
        
         <s:layout><s:HorizontalLayout/></s:layout>
        
         <fx:Script>
              <![CDATA[
                   import mx.core.IUIComponent;
                   import mx.core.IVisualElement;
                   import mx.events.DragEvent;
                   import mx.managers.DragManager;
                  
                   protected function draggableLabel_mouseDownHandler(event:MouseEvent):void {
                        DragManager.doDrag(event.currentTarget as IUIComponent,null,event);
                   }
                  
                   protected function leftGroup_dragEnterHandler(event:DragEvent):void {
                        DragManager.acceptDragDrop(event.currentTarget as IUIComponent);
                   }
                  
                  
                   protected function leftGroup_dragDropHandler(event:DragEvent):void {
                        leftGroup.addElement(event.dragInitiator as IVisualElement);
                   }
                  
              ]]>
         </fx:Script>
        
        
         <s:List id="leftList"
              dragEnabled="true"
              dropEnabled="true"
              width="200" height="200">
              <s:ArrayCollection>
                   <fx:String>Item 1</fx:String>
                   <fx:String>Item 2</fx:String>
                   <fx:String>Item 3</fx:String>
              </s:ArrayCollection>
         </s:List>
        
         <s:List id="rightList"
              dragEnabled="true"
              dropEnabled="true"
              width="200" height="200">
              <s:ArrayCollection>
                   <fx:String>Item 4</fx:String>
                   <fx:String>Item 5</fx:String>
                   <fx:String>Item 6</fx:String>
              </s:ArrayCollection>
         </s:List>
        
         <s:Group id="leftGroup"
              dragEnter="leftGroup_dragEnterHandler(event)"
              dragDrop="leftGroup_dragDropHandler(event)"
              width="200" height="200">

              <s:Rect left="0" right="0" bottom="0" top="0">
                   <s:fill><s:SolidColor color="0x00FF00"/></s:fill>
              </s:Rect>

         </s:Group>
        
         <s:Group id="rightGroup"
              width="200" height="200">

              <s:Rect left="0" right="0" bottom="0" top="0">
                   <s:fill><s:SolidColor color="0xFF0000"/></s:fill>
              </s:Rect>

              <s:Label text="DRAG ME"
                             color="0x000000"
                             mouseDown="draggableLabel_mouseDownHandler(event)"
                             y="0"/>
              <s:Label text="DRAG ME"
                             color="0x000000"
                             mouseDown="draggableLabel_mouseDownHandler(event)"
                             y="40"/>
              <s:Label text="DRAG ME"
                             color="0x000000"
                             mouseDown="draggableLabel_mouseDownHandler(event)"
                             y="80"/>
            </s:Group>
        
    </s:Application>

    DragDrop.png

    I came across a problem recently. I wanted to be able to use drag - and list controls dropEnabled property and (on the same canvas) use the functionality of drag-and-drop automatic implemented other components (in this case, a combination of movable labels that can drag a group component). I wanted the labels to be moved in the entire screen, but only fall on the part of the Group (NOT the list). The items in the components list were supposed to be interchangeable between the lists in the set of properties dragEnabled and dropEnabled to true. The problem is that when I drag the labels of the groups on the lists a null #1009 object reference error is thrown because the list does not try to calculate the index fall for labels. I know that I could work around the problem by setting dropEnabled = false on the lists and implement drag - move by hand, but I hope that both variants of drag-and-drop coexist in a spirit of flexibility.

    Any thoughts? Thank you very much!

    Kind regards

    Thilo

    When you delete something on a spark list you will need to provide a dragSource not null in the format 'itemsByIndex', if you change your code to something like this, it should work:

    protected function draggableLabel_mouseDownHandler(event:MouseEvent):void {}
                   
    do some data to pass to the list
    var someData:Vector. = new Vector. ();
    someData.push ("hello world");
                   
    List is waiting for data to slip with the format "itemsByIndex".
    var dragData:DragSource = new DragSource();
    dragData.addData (someData, "itemsByIndex");
                   
    DragManager.doDrag (event.currentTarget IUIComponent, dragData, events);
    }

  • How can I get rid of the list of people with mobility reduced/obsolete/duplicate plugins, I want more?

    O/s = XP (uptodate)
    I have various disabled plugins which are that duplicate/invalid/not wanted I want to remove from the display of the plugins list. Is there a way to do this?

    For example: I have a plugin disabled for Microsoft Office 2003. I no longer use office but the plugin still appears in my plugins list.

    Thanks in advance for your help

    See:

  • Share the list of contacts with radio

    I have a car stereo compatible bluetooth that works for media and free hand installed in my car (Pioneer DEH-X8500DAB). When I plugged my previous phone him (Samsung Galaxy S4) contacts list and call list was transferred to the main unit and I could choose a number using only the steering wheel controls.

    I searched through my premium Z5 and unit settings (contacts is enabled in the properties of the connection), but the directory on the main unit is left blank.

    Can someone suggest any bugs please

    Sorted

    I'm sure that I had already tried this solution, but it worked this time.

    I deleted the Bluetooth pairings on phone and head unit, erased all the devices of the car radio, landline to be discovered, excavated on the unit, combined, allowed to transfer the phone book and now he behaves.

    Yay for me

  • How can I get the list of recorded TV to display in columns?

    Windows Media Center displays TV recorded in columns on one of my PC and in a long horizontal flow on another PC. Both are Windows Vista.

    I finally found my own answer. In landscape view, right-click on the screen and choose "View List".

  • New to SSL VPN, can I tunnel specific networks without specifying the list of applications with Smart tunnels?

    Hello

    I'm all new to SSL VPN, and I am a bit lost... I tried to get SSL VPN to go for our company and we have been asked to deploy a completely clientless solution that will provide access to our network based on subnets. Is this possible with the chip-tunnels? I tried a few different configurations and it doesn't seem to work. It works with ANYCONNECT but we have to go without a client. They feel that we can do without customer access to destination networks. Is this possible?

    Thank you in advance...

    That's what you can do with a solution without a client:

    1. Allow access to web resources (using the url list)
    2. Allow access to the application of TCP based (using java-port forwarding or smart tunnels)

    If you have to give access to all subnets, then you will need to go full tunnel effect which is Anyconnect SSL.

    HTH

  • The list of roles with subsidies for specified schemas...

    How can I find recipients roles for each schema in my list? For example, I have about 5 patterns that each have a role of admin and user assigned to them. What I would like is a table which shows who is assigned to the roles for each schema.

    For example:

    USERS OF THE SCHEMA ROLE
    ======= =============== ==========================

    FIGURE 1 ADMIN_ROLE_SCHEMA_1 USER_1 USER_2 USER_3 USER_4

    USER_ROLE_SCHEMA_1 USER_5 USER_6 USER_7 USER_8...
    ......... .......... .......... ..........
    USER_45 USER_46 USER_47 USER 48


    FIGURE 2 ADMIN_ROLE_SCHEMA_2 USER_1 USER_2 USER_3 USER_4

    USER_ROLE_SCHEMA_2 USER_5 USER_6 USER_7 USER_8...
    ......... .......... .......... ..........
    USER_45 USER_46 USER_47 USER 48


    FIGURE 1 ADMIN_ROLE_SCHEMA_3 USER_1 USER_2 USER_3 USER_4

    USER_ROLE_SCHEMA_3 USER_5 USER_6 USER_7 USER_8...
    ......... .......... .......... ..........
    USER_45 USER_46 USER_47 USER 48


    (SORRY, I can't seem to get this to format correctly! This should be displayed in three columns, but is all stuck together when I post?)
    Thank you

    KSL

    Published by: leonhardtk on Sep 17, 2012 15:35

    Published by: leonhardtk on Sep 17, 2012 15:35

    Published by: leonhardtk on Sep 17, 2012 15:37

    Hello

    leonhardtk wrote:
    Thanks for the help; I can't quite understand your example runs... I'm running into a TOAD Editor window.

    I get an error: ORA-00923: KEYWORD not found or provided. In your example, I see a few extraneous apostrophes (second and third online and also in front of the name of the licensor. These are different than single quotes used everywhere else--is that a different symbol?

    I don't see anything like that. I used single quotes ancient Plains. Maybe your browser displays a kind of cute quotes, I used normal, straight single quotes.
    If you get a few other symbols like quote, change them to single quotes. If you get the error, your postal code.

    I just noticed that I initially failed the 2nd single in quote

    ...   OR      granted_role  LIKE ('USER\_ROLE\_%')       ESCAPE '\'
    

    now corrected. However, in your post, it seems that the error occurred earlier, because the quotes in

    ,       SYS_CONNECT_BY_PATH  (grantee, '/')     AS path          -- for debugging
    

    are not read correctly.

    Published by: Frank Kulash, Sep 18, 2012 11:00

  • Why not the AMD graphics cards on the list work supported with Premiere Pro CS6 or CC?

    I try to get my Radeon HD 7970 to work with Premiere Pro CS6.  The official compatibility list shows that I can use this card to accelerate the Mercury playback engine.  After Effects and Photoshop CS6, both recognize the card, but Premiere Pro won't.  I tried every fix there, I contacted support and they assured me that it should work with CS6 and CC.

    I tried a fresh install of my OS and a new installation cs6, and then fully implemented to update the software.  I also tried the same thing with the trial of CC, which tells me that CC is actually just CS6 who was apparently a waste of time.

    What should I do to get a support card to actually work with Premiere Pro?

    My OS is updated, I installed the latest drivers for my GPU and also tried a fresh install of the CS6 and CC... no chance whatsoever.

    The GPP setting remains greyed out, regardless of what I do.

    It seems that AMD fixed their drivers and they now work correctly with Windows 8 Pro x 64. I'm guessing that TeamViewer put pressure on those who is too generic to actually work with Premiere Pro CC.

    They work for something else, but not here...

  • the list of hosts with specific base attached?

    Hello:

    I am new to the script and hope someone will help me...

    I need to list all the host with a specific reference (on Update Manager) attached...

    I know the commands 'get-vmhost' and 'get-basic-test name', but cannot link together...

    Thank you

    You could tie these together like this 2 cmdlets

    Get-VmHost | where -filter {($_ | Get-Baseline -Name "test") -ne $null}
    

    You ask all ESX hosts and then you filter the resulting list.

    The filter passes only VmHosts with the base line 'test '.

  • The call for objects with specific CMYK values?

    Hello

    I'm trying to create a script that seeks paths that have specific CMYK values within a document and then changes the opacity of this path. I can clarify that he only looks for objects that have a CMYK color, but not getting anything once I have try to specify CMYK values, that I'm looking.

    In addition, should I specify that the output will be a "new CMYKColor", or is it sufficient to say "paths [i].fillColor.back = 100.0", for example, in the output. Here's what I have for this particular function:

    var docRef = app.activeDocument; 
    var paths = docRef.pathItems; 
    
    for (i=0; i< paths.length; i++) {
    
    if (paths[i].fillColor.typename == "CMYKColor" ) {
    
    if (paths[i].fillColor.cyan == 0.0 &&
    paths[i].fillColor.magenta == 0.0 &&
     paths[i].fillColor.yellow == 0.0 &&
     paths[i].fillColor.black == 20.0 &&
     paths[i].opacity == 100.0) {
    
    var NewColor = new CMYKColor ();
    
    NewColor.cyan = 0.0;
    NewColor.magenta = 0.0;
    NewColor.yellow = 0.0;
    NewColor.black = 100.0;
    paths[i].opacity = 20;
    }
    
    else {
    alert ("Object(s) not recognized.")
    }
    
    }
    else {
    alert ("Object not CMYK.")
    }
    }
    

    Thank you.

    Hi Silly-V,

    No, it's isn't weird.

    Illustrator is a bit crazy. Most of the values should be rounded off during playback. (as in this thread: Re: working on a script that will add a new work plan and remove the old if it is not a specific size)

    And if Luis Oyola can do something like this:

    var docRef = app.activeDocument;
    var paths = docRef.pathItems;
    
    for (i=0; i< paths.length; i++) {
        if (paths[i].fillColor.typename == "CMYKColor" ) {
            if (Math.round(paths[i].fillColor.cyan) == 0.0 &&
                Math.round(paths[i].fillColor.magenta) == 0.0 &&
                Math.round(paths[i].fillColor.yellow) == 0.0 &&
                Math.round(paths[i].fillColor.black) == 20.0 &&
                Math.round(paths[i].opacity) == 100.0) {
                    paths[i].fillColor.black = 100;
                    paths[i].opacity = 20;
                    } else {
                        alert ("Object(s) not recognized.");
                        }
                    } else {
                        alert ("Object not CMYK.");
                        }
                    }
    

    Have fun

Maybe you are looking for