Select lines based on the State of the same line

Hello

I have the following table structure and lines defind here
http://sqlfiddle.com/#! 3f474/4/3

I want Select if lines
PRODUCT_NO
is null, then I need to select rows that have the IS_PAYABLE = 'Y '. If
PRODUCT_NO
is not null
then IS_PAYABLE will be ' no or IS_PAYABLE will be null.

For example
For PRODUCT_REG HPO_FABRIC, a
PRODUCT_NO
NULL if I need select this line only, not the other two rows.
I can do
select * from SUPPLIER_DETAILS where  IS_PAYABLE='Y'
, but if there are many records with null or not null PRODUCT_NO

How can I do this using sql?
select
  PRODUCT_REG,
  PRODUCT_SUPPLIER_CODE,
  PRODUCT_NO,
  START_DATE,
  END_DATE,
  IS_PAYABLE
from (
select
  PRODUCT_REG,
  PRODUCT_SUPPLIER_CODE,
  PRODUCT_NO,
  START_DATE,
  END_DATE,
  IS_PAYABLE,
  row_number() over (partition by product_reg order by decode(is_payable,'Y',1,'N',2,3), product_no nulls first) rn
from
SUPPLIER_DETAILS
)
where
rn = 1

PRODUCT_REG     PRODUCT_SUPPLIER_CODE     PRODUCT_NO     START_DATE     END_DATE     IS_PAYABLE
HPO_FABRIC     JP_008     -      08/01/2001     08/31/2001     Y
STG_PIL     SJ_090     STG-PILLOWS     01/04/2001     01/31/2001     - 

Published by: chris227 on 17.09.2012 13:30

Tags: Database

Similar Questions

  • Select data based on the priority of the State

    ID PRO_ID PRO_OBJ_ID TASK_ID DEVELOPER_ID STATUS
    121243 4940 37506 5250 6532 REJECTED
    122063 4940 37506 5250 6532 RELATIVES
    138306 4940 37506 5250 6532 ACCEPTED
    138307 4940 37506 5250 6532 WIP




    Hello

    In the table above, I need to select data based on the State, a status which precedes CLOSE or ACCEPTED it should display all status any State which is after CLOSE or ACCEPTED, we do not consider.


    In the scenioro above, it should display only the status of first three. After having ACCEPTED, it should not display something


    Please suggest me a request how to write.


    Thank you
    Sudhir.

    Try:

    SQL> with t as (
      2  select 121243 id, 4940 pro_id, 37506 pro_obj_id, 5250 task_id, 6532 developer_id, 'REJECTED' status from dual union all
      3  select 122063, 4940, 37506, 5250, 6532, 'CLOSE' from dual union all
      4  select 138306, 4940, 37506, 5250, 6532, 'ACCEPTED' from dual union all
      5  select 138307, 4940, 37506, 5250, 6532, 'WIP' from dual union all
      6  select 138308, 4940, 37506, 5250, 6532, 'ACCEPTED' from dual union all
      7  select 138309, 4940, 37506, 5250, 6532, 'REJECTED' from dual union all
      8  select 121243, 4940, 37777, 5250, 6532, 'REJECTED' from dual union all
      9  select 122063, 4940, 37777, 5250, 6532, 'CLOSE' from dual union all
     10  select 138306, 4940, 37777, 5250, 6532, 'ACCEPTED' from dual union all
     11  select 138307, 4940, 37777, 5250, 6532, 'WIP' from dual union all
     12  select 138308, 4940, 37777, 5250, 6532, 'ACCEPTED' from dual union all
     13  select 138309, 4940, 37777, 5250, 6532, 'WIP' from dual
     14  ) -- actual query starts here:
     15  select t1.id
     16  ,      t1.pro_id
     17  ,      t1.pro_obj_id
     18  ,      t1.task_id
     19  ,      t1.developer_id
     20  ,      t1.status
     21  from   t t1
     22  where id <= (select max(id)
     23               from   t t2
     24               where  t2.status in ( 'ACCEPTED', 'CLOSED' )
     25               and    t1.pro_id = t2.pro_id
     26               and    t1.pro_obj_id = t2.pro_obj_id
     27               and    t1.task_id = t2.task_id
     28               and    t1.developer_id = developer_id
     29               );
    
            ID     PRO_ID PRO_OBJ_ID    TASK_ID DEVELOPER_ID STATUS
    ---------- ---------- ---------- ---------- ------------ --------
        121243       4940      37506       5250         6532 REJECTED
        122063       4940      37506       5250         6532 CLOSE
        138306       4940      37506       5250         6532 ACCEPTED
        138307       4940      37506       5250         6532 WIP
        138308       4940      37506       5250         6532 ACCEPTED
        121243       4940      37777       5250         6532 REJECTED
        122063       4940      37777       5250         6532 CLOSE
        138306       4940      37777       5250         6532 ACCEPTED
        138307       4940      37777       5250         6532 WIP
        138308       4940      37777       5250         6532 ACCEPTED
    
    10 rows selected.
    

    If it works then please provide us with some representative sample data again.

  • Select literal values in the same column

    Hello
    like the practice:

    Select 'A', 'B', 'C' for double
    will select these values in their own column on the same line, is there a simple way to select these values in the same column on lines without first their insertion into a table?

    Thank you
    SQL> select 'A' x from dual union
      2  select 'B' x from dual union
      3  select 'C' x from dual ;
    
    X
    -
    A
    B
    C
    

    A bit complicated:

    SQL> select chr(ascii('A')+level-1) x
      2  from dual
      3  connect by level <=3;
    
    X
    -
    A
    B
    C
    

    Other:

    SQL> select regexp_substr('ABC','[[:alpha:]]',1,level) x
      2  from dual
      3  connect by level <= length('ABC');
    
    X
    ---
    A
    B
    C
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 12, 2010 17:55
    added a second

    Published by: Massimo Ruocchio, February 12, 2010 17:58
    Added the third

  • How to select multiple cells at the same time?

    Hello

    How to select multiple cells at the same time? What is the keyboard shortcut?

    Thank you to.

    Flo, a french guy.

    Hold down the CMD key when you select the cells.

  • When exporting my image in LR I select my brand of water in the drop-down list. Then I need to select 'Edit watermark' since the same drop-down menu in order to replace it. When I do that and click 'done' the watermark disappears in the export me

    When exporting my image in LR I select my brand of water in the drop-down list. Then I need to select 'Edit watermark' since the same drop-down menu in order to replace it. When I do that and click 'done' the watermark disappears in the box menu to export. When I click on "Export" the image exports WITHOUT my watermark. Help, please. As I did about everything that has been suggested in this forum and I still have this problem.

    I saw that too. For now, the workaround is that if you select 'Edit watermark,' when you are done editing be sure to reselect the same watermark. If you do not, the watermark menu will be empty.

    It seems to be a known bug that occurs only in the current version. If all goes well, it can be fixed in the next update. There is a page for her on the Photoshop/Lightroom Feedback site. I've added my vote to the page:

    LIGHTROOM CC - watermark on the question of export

  • Why are on the first web page are buttons and following pages Don t-shaped? All Pages are based on the same Masterpage.

    Hello

    I ve a problem with Muse.

    Why are on the first web page are buttons and following pages Don t-shaped? All Pages are based on the same Masterpage.

    Any ideas?

    Stefan

    Hello Stefan,

    Could you please share your with us .muse file to study? Please send it to [email protected]. If your file is larger than 20 MB, you can use something like Adobe SendNow SendThisFile or Dropbox. Don't forget to mention the link to this forum thread in your email so that we can identify the file.

  • Same page, two regions based on the same conflicts taskflow

    I have a page and I understand two regions based on the same workflow, at the start of region renderes ok, but then they don't are never refreshed, it seems like a conflict.

    I hope you can help me, thanks and sorry for my English...

    Published by: Jocelyn on 2012-ene-18 09:13

    Hello

    Well, I don't understand the question "no refresh" you mention. However, you did it that the workflow is isolated and does not share its DataControl? If you share the DataControl then region 1 and 2 show the same data and are just one and same.

    Frank

  • They are based on the same principle?

    Are the Oracle coherence and Oracle Cluster Cache Fusion based on the same principle?
    They work the same way?

    Thank you

    Hi Frank,.

    Oracle coherence cache and Cache Fusion of Oracle RAC are not based on the same principle and are not in the same way. It is true that both provide features "hidden" in a 'cluster', but that's where the similarity ends.

    Kind regards

    Harv

  • Check box selected property based on the EL Expression

    Hello

    I create adf table with af:selectBooleanCheckbox in the first column. the checkbox from always refreshable transitional attribute (boolean).

    in the same point of view, I have an Id attribute also.

    I want to set enabled status this box according to the Id, when I tried to change the selected checkbox true property always, all checkboxes checked and I can change the State active or non-active normally, but when I put an EL expression (#{bindings.) ID not null? ({"true": "false"} box normally checked but becomes readonly!).

    can someone help me?

    using jDev Studio Edition Version 12.1.3.0.0

    I think so

    You check or uncheck the box according to the value in VoRowimpl iteslf.

    It would be nice.

    Concerning

    Vincent

  • Poller DB to select records based on the timestamp

    Hi all

    I want select records from the coloumn timestamp where the timestamp is older than an hour. Is it possible to do this through poller db? I tried but unable to pass the dynamic value (currently - 1 hr)

    Thanks in advance!

    Eventually create a view based on the timestamp and singled out the dbpoller view.

  • When selecting several fields of the same type why tab formatting does not appear in the properties?

    Creating pdf with lines Qty and total order forms, I want to format the fields as number with 0 decimal places for the qty column and the sign $ and 2 decimals for the totals column.

    Why when choosing several fields quantity, then go to properties, the format tab disappear? Why do I have to choose and the format of each field one at a time? They have the same type of field.

    I'm working currently on a document with more than 200 fields are most of the quantity fields and others are total fields. I right click on each field individually.

    It's 2015! Can you imagine if Excel did it?... Adobe WTF?

    Only the Adobe developers can answer why it is like that, but it's unfortunately.

    The only solution is to use a script to set the Format setting for several fields at the same time.

    I developed such a tool, so if you are interested you can get it here: Scripts custom Adobe: Acrobat - Format applies to several text fields

  • Select all objects with the same style of object?

    I did some research but empty is come. It is possible to select all the objects on a page that have the same style of applied object?

    What I want to do, is apply an action 'frame content' to a large group of text boxes (labels on a map). But this mounting option doesn't seem to be available as part of the style of the object.

    Any suggestions?

    Thank you.

    Try using the option Auto-size text block rather in the style of the object. This feature (found in the object > text frame Options) is useful to the legends of autosize following certain rules.

    This attribute can be used in object styles.

  • Selection of records in the same table problem

    Hi all

    I have the following table
    with emp as (
               select '11' A,'aaa' B, '40' C from dual union all
               select '11','bbb', '40' from dual union all
               select '33','ccc', '30' from dual union all
               select '44','ddd', '20' from dual union all
               select '11','eee', '10' from dual
              )
    My results should be
    A           B        C
     
    11        aaa      40
    11        bbb     40      
    11        eee     10
    Basically the requirement is select different combination of values in the column 'B' need to know what is the value of 'A' (it must be the same for all records of three)


    Hope in this sense.


    See you soon

    Sexy

    an attempt to rephrase:

    you want all the files "aaa", "bbb" and "EEA" where, for each set of column A, where they exist.

    that is, if games to have only "aaa" and "bbb" but not "eee" in column B, then you don't want to retrieve this record?

    Try this:

    SQL> with emp as (
      2  select '11' A,'aaa' B, '40' C from dual union all
      3  select '11','bbb', '40' from dual union all
      4  select '33','ccc', '30' from dual union all
      5  select '44','ddd', '20' from dual union all
      6  select '11','kkk', '20' from dual union all
      7  select '10','eee', '20' from dual union all
      8  select '11','eee', '10' from dual
      9  )
     10  select a, b, c
     11   from (select emp.*, count(*) over (partition by a) cnt
     12    from emp
     13   where b in ('aaa','bbb','eee'))
     14   where cnt = 3
     15  /
    
    A                                B                                C
    -------------------------------- -------------------------------- --------------------------------
    11                               eee                              10
    11                               aaa                              40
    11                               bbb                              40
    
    3 rows selected.
    

    Published by: WhiteHat June 30, 2011 11:04

  • Based on the same Page of each tab and don't delete. Need help!

    [UPDATED BELOW WITH THE SOLUTION]

    The best way I can describe what I'm trying to achieve is the native music BB10 application navigation structure.

    Once you click on a track, you have to push the "Now Playing" view, and then that you go back to the navigation of your library, you can return to this view via a thumbnail image in the title bar. Of course, the view is not destroyed, that the page is running the music. But as you will see, this miniature in the title bar can be found in all the tabs and push the view "Now Playing" no matter what tab, you're in.

    I find it impossible to reproduce. I have a NavigationPane in each of my tabs, and maintain a single instance of the "Now Playing" view in the variant of nowPlayingView property. All seen below in my main.qml file:

    import bb.cascades 1.0
    
    TabbedPane {
        property variant nowPlayingView: nowPlayingComponent.createObject()
        Tab {
            id: tab1
            NavigationPane {
                id: navPane1
                FirstView {
                }
            }
        }
        Tab {
            id: tab2
            NavigationPane {
                id: navPane2
                SecondView {
                }
            }
        }
        Tab {
            tab3
            NavigationPane {
                id: navPane3
                ThirdView{
                }
            }
        }
        Tab {
            tab4
            NavigationPane {
                id: navPane4
                FourthView{
                }
            }
        }
        attachedObjects: [
            ComponentDefinition {
                id: nowPlayingComponent
                source: "NowPlaying.qml"
            }
        ]
    }
    

    Then, all pages, it is easy to access the nowPlayingView and push it through the respective navPane. The code below is from FirstView.qml which is in tab 1.

    navPane1.push(nowPlayingView);
    

    The problem is that I can successfully push this nowPlayingView one of the tabs, as long as it's the first time. So if I push everything first using navigationPane of Tab1, I am unable to shoot from all others, but it can grow as many times I want again on Tab1. The same applies if I pushed first view of the Tab2.

    How can I push this view of one of the tabs, while not to delete the page each time it is released. Please, please, any help would be appreciated. Just check out the music app native bb10 to understand the flow of navigation that I try to imitate. And as I understand it, it is not possible to use a single navigationpane for all tabs.

    Thank you!

    [CODE WORK] thanks to Zmey!

    QML, before pushing the view I must remove its previous parent by calling on C++.

    app.removePageParent(mediaView);
    navPane.push(mediaView);
    

    Using this helper function from C++ to remove the parent of the page

    void ApplicationUI::removePageParent(QObject *o) {
        //qDebug() << "removing page parent";
        o->setParent(NULL);
    }
    

    It will be for some reason doing two "back" button when you press the view again (bug sdk). To resolve this issue, manually set the back button.

    paneProperties: NavigationPaneProperties {
            backButton: ActionItem {
                onTriggered: {
                    mediaView.parent.pop()
                }
                title: "Back"
            }
        }
    

    I hope this helps someone! All creds to Zmey!

    Hello

    push() method description mentions that the parent of the page must be null or NavigationPane to which the page is pushed in.

    Try setting page.parent to null before pushing the page (this also can be done in NavigationPane onPopTransitionEnded).

    UPD: it did not work because the parent is readonly in QML. We had to make a C++ helper function and use setParent().

  • Select texts based on the option "customer tracking/kerning.

    Hi all

    If it is possible to push all the texts of tracking/kerning table? If it is possible to attack with highlighting of text as shown below?

    Screen shot 2015-05-05 at 5.11.34 PM.png

    Screen shot 2015-05-05 at 5.12.36 PM.png

    So I put together a few lines.

    Try them and tell me if it points in the right direction.

    To use the Script, you need an InDesign file with text. Some characters have kerning (-100). On top, you need a character style in the InDesign document with the name of "red". If you change the color in the character style, you should see that the characters with kerning (-100) have given color after you run the script.

    Kind regards

    Daniel (from Switzerland)

    main();
    exit();
    
    function main() {
    
        // if there is an open document in InDesign
        if (app.documents.length > 0) {
            var myDoc = app.activeDocument;
    
            // get the selected text
            var mySel = myDoc.selection[0];
    
            if ((mySel != null) && (mySel.constructor.name == "Text")) {
    
                // create an array
                var charArray = new Array();
                alert("information \nText selected");
    
                alert("Information\n# characters selected: " + mySel.characters.length);
    
                for (var i = 0; i < mySel.characters.length; i++) {
                    var myChar = mySel.characters[i];
    
                    // if the kerning was changed
                    if (myChar.kerningMethod == "Manual") {
    
                        // output to the console
                        $.write("Character: >" + myChar.contents + "< kerning: " + myChar.kerningValue);
    
                        // if the kerning is -100 or  less
                        if (myChar.kerningValue < -99) {
    
                            // apply characterstyle to found characters no array needed
                            myChar.appliedCharacterStyle = myDoc.characterStyles.item("red");
                            $.writeln(" OK got it");
    
                            // push character into array
                            charArray.push(myChar);
                        }
                        else $.writeln();
                    }
                }
                alert("Information\nCharacters with kernig -199 found: " + charArray.length);
            }
            else alert("Warning\nNoting or no text selected");
        }
        else alert("Warning\nno document open");
    
        alert("Information\nI did my job, what about yours?");
    }
    
  • Select records based on the monthly anniversary date

    Hello

    I have a table with a field of date_added and I want to select records from monthly birthday of this field.

    for example. ID, Date_added
    1, DECEMBER 10, 2012
    2, 11 NOVEMBER 2012
    3, 10 MARCH 2012
    4, FEBRUARY 28, 2012
    5, 30 DECEMBER 2012

    So for January 10, 2013, I would like to return the documents 1 and 3 only

    I started watching the extract function, but this little falls down to the records at the end of the month. For example, on 28 February, I also include records where 29, 30 or 31 is the day of date_added. So, in the above table, I won't return documents 4 and 5, but retrieves only returns 4.

    Is there a simple function to make the request of birthday this month - have I missed something very obvious? Or I have to write a query to explicitly dates at the end of the month? So far I have not found a reasonable solution!

    I use 11g

    Thank you

    user11259857 wrote:
    Hi Al,.

    No I don't think that there is a flaw. For example, the 30 Jan is not the last day of the month, but is June 30. Thus, on 30 January I want only to interrogate all the dates falling on the 30th - 28 February, after already being interrogated on the 28 Jan. However, on 30 June, I would query the 30th of each month, as well as the 31 January, March, may, July, Aug, Oct, dec. February is a special case, being both shorter and a leap year

    Thank you

    Richard

    Hi Richard,

    so, we can assume that your needs are:

    If the day is the last day of that month, interview the day of the other months being > = day of the current month.

    That is to say:

    Jan-30 = query only 30 other months
    Jan-31 = query only 31 of the other months

    Feb-28 (non-leap years) = question 28, 29, 30 and 31 other months
    29 February (leap year) = query 29,30,31 to other months

    Mar-30 = query only 30 other months
    Apr-30 = query 30 and 31 other months

    This hypothesis is correct?

    If so, then something like this should work:

    WITH mydates(id, date_added) AS
    (
       SELECT 1, TO_DATE('10-DEC-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 2, TO_DATE('11-NOV-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 3, TO_DATE('10-MAR-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 4, TO_DATE('28-FEB-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 5, TO_DATE('30-DEC-2012', 'DD-MON-YYYY') FROM DUAL
    )
    SELECT id, date_added
      FROM mydates
     WHERE (:input_date = LAST_DAY(:input_date) AND TO_CHAR(:input_date,'DD') <= TO_CHAR(date_added, 'DD'))
        OR TO_CHAR(:input_date,'DD') = TO_CHAR(date_added, 'DD');
    
    with input_date = 28/02/2013
    
    id   date_added
    4    28/02/2012
    5    30/12/2012
    

    Kind regards.
    Al

    Published by: Alberto Faenza on 10 January 2013 15:21
    Added example

Maybe you are looking for

  • New hard drive installed on Portege M200 but does not start

    I upgraded the hard drive in my Portege M200 from 4 GB to 80 GB using Parted Magic to clone the original disc. Cloning complete successfully, but instead of starting with the new drive, the M200 simply display a blinking cursor when turned on. Any he

  • Problems burning DVD - dm4 3010 tx - win 7 64 bit SP1

    Hey I use a dm4 3010 tx - win 7 64 bit SP1 portable computer. I can't burn files to DVD, I can play DVDs fine. I tried with 2 software: => Burner(error message in image) Windows disk -Online Imgburn: error message - disc finalization failed Any sugge

  • Cannot install the printer error Code 707

    Original title: Error Code 707 Hello I am trying to install a Kodak ESP C315 printer and continue to receive the error code 707: 'D:Setup\KapMaster.exe"/m.\CompanyName="Eastman Kodak Company' code '1033' / X = 0 Y = 0.  Can you help me please?  I was

  • I can't delete my email in outlook express 6.

    This problem started a month ago, but he has only done a few emails. Then I downloaded Norton from comcast and my box of deleted messages had emptied himself and now I can't transfer all items in the deleted box.

  • Error Microsoft Visual C++ Runtime Library, opening of PDF files

    I'm on Windows Vista Edition Home Premium.  I have a problem trying to open PDF files on my drive hard or via IE.  I get the error message says: "Microsoft Visual C++ Runtime LibraryRuntime error!Program: C:\Program 9.0\Reader\AcroRd32.exe Adobe This