Group by based on condition

Database: SQL Server 2000 Enterprise edition

OS: Windows Server 2003


Huh?  Everyone will ask me why I write question of SQL Server in the Oracle forum?  I'll answer something like this:


My friend is actually SQL Server DBA and it becomes a problem to solve the query below.  He asked me to solve in Oracle 9i (because since it uses SQL Server 2000, so I guess it's almost similar level) and/or through pure SQL. but I'm really very poor in SQL (must read the docs several times); I have no help.  He just asked me how to solve in Oracle and if it's solved in Oracle, then he will try to solve by looking at similar function in SQL Server features, etc.  Even if I posted the question in the two instances of SQL Server, but there are probably less activity, so I post here:


create table students

(

rollno int,

name varchar (30),

class varchar (20)

);

insert into student values (1, 'Robert', 'IT');

insert into student values (2, 'John', 'Arts');

insert into student values (2, 'Hussain', 'IT');

insert into student values (1, 'David', 'Science');

insert into student values (3, 'Polo', 'IT');

insert into student values (2, 'Jonathan', 'Science');

insert into student values (4, 'Joseph', 'History');

insert into student values (1, 'Richard', 'History');

insert into student values (1, 'Michel', 'Trade');

insert into student values (1, 'Albert', 'Geography');

SQL> select * from student;

    ROLLNO NAME                           CLASS
---------- ------------------------------ --------------------
         1 Robert                         IT
         2 John                           Arts
         2 Hussain                        IT
         1 David                          Science
         3 Polo                           IT
         2 Jonathan                       Science
         4 Joseph                         History
         1 Richard                        History
         1 Michel                         Commerce
         1 Albert                         Geography

10 rows selected.

SQL>

Power required:

rollno  name        class
1        Robert      IT
2        Hussain     IT
3        Polo        IT
4        Joseph      History

Required output logic: Rollno must be unique for all classes giving priority to:

1.IT
2.Science
3.Arts
4.Commerce
5.Geography
6.Anyone

means, if suppose we get a number unique roll (x) and if it exists in all classes, then first of all, it should be HIM, and if it's not in there, then it should search in the Science class, if it is not in and of science courses, then it must search the Arts class If is not in, science, Arts, then you should look for in the category of trade; like wise. All existing issues of the roller must be unique among all classes giving priority to IT, science, Arts, Commerce, geography and if this unique roll number is not above 5 classes, it can be a category any.

Kindly let me know, if I'm unclear in my question or must provide more details. Because my friend is using SQL Server 2000, so I would ask you please help me/him using SQL simple please.

Thanks and greetings

Girish Sharma

Probably need to several test cases:

SELECT ROLLNO, NAME, CLASS

FROM (SELECT a.*,

(RANK)

DURING)

PARTITION BY rollno

ORDER BY

(CASE

WHAT class 'IT' = 1 THEN

WHAT class = 'Science' THEN 2

WHAT class = 'Arts' THEN 3

WHAT class = 'Trade' THEN 4

WHAT class = 'Geography' THEN 5

6. OTHER

END))

RNK

One STUDENT)

WHERE rnk = 1;

ROLLNO NAME CLASS

1 Robert HE

2 IT Hussain

Polo 3 IT

Story of Joseph 4

See you soon,.

Manik.

Tags: Database

Similar Questions

  • Based where conditional clause...

    dear team,
    i have following code..
    
    Declare
      gv_flag1 Varchar2(1)   := 'N';
      gv_flag2 Varchar2(1)   := 'N';
      gv_flag3 Varchar2(1)   := 'N';
      all_where1       Varchar2(250);
      all_where2       Varchar2(250);
      ALL_where3       Varchar2(250);
      V_QTY           Number;
    Begin
      If gv_flag1 = 'N' Then
         all_where1 := 'AND '||'V.OWNER = ''PROD''';
      End If;
      DBMS_OUTPUT.PUT_LINE(all_where1);
      
      If gv_flag2 = 'N' Then 
         all_where2 := 'AND '||'V.OPERATION NOT LIKE (''10%'')';
      End If;   
      DBMS_OUTPUT.PUT_LINE(all_where2);
      
      If gv_flag3 = 'N' Then
         all_where3 := 'AND '||'V.OPERATION NOT LIKE (''07%'')';
      End If;
      DBMS_OUTPUT.PUT_LINE(all_where3); 
       
      --select based on conditions..
    End; 
    
    NOW I want where conditions in select statment to be conditional...
    
    which means if flag1='N' and flag2 = 'N' then use both all_where1 and all_where2 in *where* clause statement...
    if flag1='N' and flag3 = 'N' then then use all_where1 and all_where 3 in *where* clause of select statement...
    if all there flag = 'N' then use all_where conditions in *where* clause of select statement...
    
    i have 3 flags, which means total of 9 combinations,  is there any simpler way to do such kind of thing??
    
    please assist me
    
    nic

    Nicloei W wrote:
    Hi Jeenesh,

    What happens if Flag2 = 'Y' and Indicateur3 = 'Y' in this case, I want only the condition with Flag1

    concerning
    NIC

    SQL> ed
    Wrote file afiedt.buf
    
      1  Declare
      2    gv_flag1 Varchar2(1)   := 'N';
      3    gv_flag2 Varchar2(1)   := 'Y';
      4    gv_flag3 Varchar2(1)   := 'Y';
      5    --all_where1       Varchar2(250);
      6    --all_where2       Varchar2(250);
      7    --ALL_where3       Varchar2(250);
      8    lc_query varchar2(1000):= 'select count(*) from test v ';
      9    lc_where varchar2(500) := ' where 1 = 1 ';
     10    V_QTY           Number;
     11  Begin
     12    If gv_flag1 = 'N' Then
     13       lc_where := lc_where||' AND V.OWNER = ''TEST''';
     14    End If;
     15    If gv_flag2 = 'N' Then
     16       lc_where := lc_where||' AND V.OPERATION NOT LIKE ''10%''';
     17    End If;
     18    If gv_flag3 = 'N' Then
     19       lc_where := lc_where||' AND V.OPERATION NOT LIKE ''07%''';
     20    End If;
     21    lc_query := lc_query||lc_where;
     22    dbms_output.put_line(lc_query);
     23    dbms_output.put_line('-----------');
     24    execute immediate lc_query into v_qty;
     25    dbms_output.put_line('Count: '||v_qty);
     26* End;
    SQL> /
    select count(*) from test v  where 1 = 1  AND V.OWNER = 'TEST'
    -----------
    Count: 3
    
    PL/SQL procedure successfully completed.
    
  • Chronology of trigger has to play based on conditional

    I'm working on a project in which I have four draggables, able to receive four and four default droppable in the composition.  Once these four individual draggables were abandoned on the beneficiaries of their point of view I want to trigger a symbol to play his chronology based on a conditional statement that checks that all four draggables were deleted correctly.

    To do this, I pushed the four movable in a table after groups that they were interrupted and movable destroyed using the jquery ui library.  I know that the table is filled because I get the appropriate groups in the console and the length of the table.

    I tried to make a loop for to analyze the table and feed than an if statement to verify that it has four points and trigger the chronology of symbol reading.  Only problem is that it doesn't.  Do you have advice on how to solve the problem of the code below?

    correct=[];

    //DRAGGABLE RIDE TO AIRPORT GROUP

    sym.$('rideGroup').draggable({           containment:'parent',           scope: 'task3',           opacity:.9,            revert:'invalid',            zIndex:6 });

    //Make the targetRide area droppable and accept the Ride to Airport Group

    sym.$('targetRide').droppable({

          scope:'task3',

          drop: function(event, ui){

               accept: 'rideGroup'

               tolerance:'fit'

               draggable:'destroy'

               correct.push('rideGroup');

          }

    });

    sym.$('defaultRide').droppable({

          scope: 'task3',           drop: function(event,ui){

               accept: 'rideGroup'

               }

         });

    for(var i=0; i <= correct.length; i++){

          if(i === 4 && correct.length === 4){

               sym.getSymbol('Animation').play('greatJob');

          }else{           sym.getSymbol('Animation').play('notRight');

       }

    };

    If I take the line code sym.getSymbol in the conditional statement and place it where the push instruction has, each of the draggables play the timeline after a fall.  We're not that good.  We have the timeline plays that once all four of the draggables were dropped.  I've included the code for one of the moveable and sets able to receive here for reasons of space only.

    Thanks for any help you can provide.

    K lies in case handler - so when the event occurs, k is incremented and when it equals the number of events (the draggables that are well placed) it does what you want it to do, in this case an animation. This could be used for something else if you wanted to.

    The position can use left, high, mid, low, Center... I would not add pixels to it. It is best to get the placement in this way. If you have images that have limits of the strange, you could use transparent droppable on images. Hope it makes sense.

  • Groovy aggregate function based on condition

    Hi all

    I use jdev 12.1.3.0.0

    I've set up an aggregate function in my master EO as explained in the blog

    https://blogs.Oracle.com/ADF/entry/using_groovy_aggregate_functions_in

    I need to add a condition to the number of records based on an attribute of the object of details view. Algorithm for the use case is

    detailsAccessor.count ("SmsId")

    where detailsAccessor.MessageType is equal to "file."

    Could you help me write an expression to achieve this functionality.

    Thank you

    Mozakkir

    All aggregate in groovy functions accept a groovy as a parameter expression.

    So instead of detailsAccessor.count("SmsId") you can try something like: detailsAccessor.count ("MessageType is 'Applicant'")

    Or convert sum() like this: detailsAccessor.sum ("MessageType is"Applying"? 1: 0 ")"

    Dario

  • How to keep the alignment of a group logo based on four elements?

    I created and aligned a logo based on four letters. Subsequently I've grouped. The alignment is correct. But if I copy the Group and place it in a different location, alignment falls slightly out of place. What should I do to keep the aligned group?

    Thank you for answer

    Angelika

    I see two things that could cause this.

    First of all is to line up on the starting grid. If enabled for a letter, but not others, you may see changes in the vertical postioning of this letter of treation to others. If applied to all you letters could find, you cannot position the logo vertically accurate spot you want. More likely, however, you would see one or several letters go in excess at least executives were very deep.

    Second is text wrapping. If the letters are individual images, they would be individually affected by the text applied to another object wrapping. You could overcome this by turning on "Ignore the text of not dress" for images of logo in the text frame options.

    Other things you could do: convert the text to outlines text. When you convert to outines you have editable text, and it is not subject to the skin or the complications of grid planning.

    Or create the logo in a second document and export to PDF, then place the PDF file. It will behave like a picture. If you need be able to easily modify the logo, save it in a separate ID doc and place the page of the .indd. The original update will update the copy placed.

  • GROUP BY IN FILTER CONDITIONS

    Hello

    I'm trying to filter the report based on the account number and year, for specific account numbers, that I want the limit by fiscal 2010, for others I want every year starting in 2007. How can I group under filters in OBIEE.

    Ex: for numbers 1000, 1001, 1002, 1003 account I want to pull records for the year 2010. For 7000, 7003, 7700 account numbers I want to shoot in 2007, 2008, 2009.

    I'm new to OBIEE. Need help.

    Thank you.

    You can create a new column in response to logic

    Case when account_numer in (1000, 1001, 1002, 1003) and  year in (2010) then 1
           when account_numbers  in (7000, 7003, 7700 ) then year in (2007, 2008, 2009) then 1
    else 2
    end
    

    Now apply filter on the column where the value = 1

    See you soon
    Katia

  • He had to find the way of the table based on conditions...

    Hello

    Please look at the specimen below...
     
    AMOUNT      ID NO             Date
              
    588     0000053125     07/01/09
    612     0000053125     06/01/09
    528     0000053125     05/01/09
    635     0000053125     04/01/09
    700     0000053125     04/02/09
    588     0000053126     07/01/09
    612     0000053126     06/01/09
    528     0000053126     05/01/09
    635     0000053126     04/01/09
    700     0000053126     04/02/09
    588     0000053127     07/01/09
    612     0000053127     06/01/09
    528     0000053127     05/01/09
    635     0000053127     04/01/09
    700     0000053127     04/02/09
    588     0000053128     07/01/09
    612     0000053128     06/01/09
    I need to know the average of (AMOUNT) of the last three months, based on the given ID no..
    Please note that for the registration of the sample, there are only 3 ID no.... but in real time will come more ID no..

    Note:
    ID no. 0000053128 is to have only two recordings... here, the average should be calculated accordingly.

    Hello!

    It should provide AVG ol 3 last records (assuming that you have in your data in a record for a month)

    SELECT id_no, AVG(amount)
       FROM (SELECT amount, id_no, date1, row_number() over(PARTITION BY id_no ORDER BY date1 DESC) rn
                    FROM Your_table ORDER BY id_no, date1 DESC )
    WHERE rn <= 3 GROUP BY id_no
    

    T

  • How to change the color of line based on Condition

    Dear all,

    We have requirment as shown below

    Based on the condition, I want to show the color for all of the line

    Example of

    If attribute = 'Y' then
    {
    < show the color for complete line in advanced table?
    }

    Please give me suggestion how join my requirment.

    Thank you
    Venkat Reddy Pulichintha

    Hey...

    you said that the code you wrote is working for a column... in the same way you can set the CSS Style on all other columns as well...

    Why don't you go with code that works...

    DataBound APIs are an alternative solution to this... you can search on it later...

    Thank you
    Gerard

  • set of results based on condition

    Hi all

    I have a requirement that contains three conditions which means my final result set is derived
    3 different conditions.
    I have three tables and I Union to get the result set.
    ex:
     Select cust_id, cust_name , cust_add, 'A' condition  
                From  Table1 {CODE}
             union
                Select cust_id, cust_name , cust_add, 'B' condition
                  From  Table2
             union
                Select cust_id, cust_name , cust_add, 'C' condition
                  From  Table3                                                         
       Values are:
                   cust_id           cust_name                cust_add           condition
                     100               roy                       ABC                   A
                     100               roy                       ABC                   B
                     101               eddy                                            C
                     102               pat                                             B
                     102               pat                                             C
    Instead of having the same information on two different lines, I want to have the same line with 2 another column showing what conditions he met.
       i require values like this:
                    cust_id           cust_name               cust_add           condition1          condition2        condition3
                     100               roy                       ABC                   A                   B
                     101               eddy                                            C
                     102               pat                                             B                   C
    Can someone help me to achieve this type of result set.
    Thank you!

    Hello

    This is called a pivot

    WITH     union_query     AS
    (
         Select cust_id, cust_name , cust_add, 'A' condition
                From  Table1 {CODE}
             union
                Select cust_id, cust_name , cust_add, 'B' condition
                  From  Table2
             union
                Select cust_id, cust_name , cust_add, 'C' condition
                  From  Table3
    )
    ,     got_rnum     AS
    (
         SELECT     union_query.*
         ,     ROW_NUMBER () OVER (PARTITION BY cust_id)     AS rnum
         FROM     union_data
    )
    SELECT       cust_id,      cust_name,     cust_add
    ,       MAX (CASE WHEN r_num = 1 THEN condition END)     AS condition1
    ,       MAX (CASE WHEN r_num = 2 THEN condition END)     AS condition2
    ,       MAX (CASE WHEN r_num = 3 THEN condition END)     AS condition3
    FROM       got_rnum
    GROUP BY  cust_id,      cust_name,     cust_add
    ORDER BY  cust_id,      cust_name,     cust_add;
    

    It's a bit more complicated than some points of articulation, because there is nothing in your raw data that tells you which column of output directly each condition belongs in. (in other words, for the results you requested, a 'C' could go to condition1 or condition2 and condition3: just by looking at the line with the 'C' we cannot tell who.) We do this by using the function ROW_NUMBER analytic, and, like a lot of things involving analytic functions, which requires a separate subquery.

  • Delete a duplicate based on conditions

    Hello
    < div style = "border: 1pt solid windowtext;" Padding: 1pt 4pt ">"
    {size: 9pt} SQL & gt; Select * from
    version of v$. {size}


    {size: 9pt} BANNER
    ----------------------------------------------------------------{size}


    {size: 9pt} Oracle Database 10g Express
    Edition Release 10.2.0.1.0 - product {size}


    {size: 9pt} PL/SQL Release 10.2.0.1.0-
    Production {size}


    {size: 9pt} CORE 10.2.0.1.0 Production {size}


    {size: 9pt} AMT for 32-bit Windows:
    Version 10.2.0.1.0 - Production {size}


    {size: 9pt} NLSRTL Version 10.2.0.1.0 & ndash;
    Production {size}

    < / div >


    You need to remove the lines that is duplicated in the Oracle table.

    Source
    -----
    EMPID NAME CYI
    -----
    1001. A MACH1
    1001. A MACH2
    1002 B MAH1
    C 1002 MAH1
    1002. A MAH1
    1003 X MACH12
    1003 X MACH1

    Output:

    -----
    I want to just delete a duplicate based on CYI = "MAH1.

    EMPID NAME CYI
    -----
    1001. A MACH1
    1001. A MACH2
    1002 B MAH1
    1003 X MACH12
    1003 X MACH1

    I tried with this request, but she considers in fact all duplicaes table...

    DELETE FROM test00 WHERE rowid NOT IN (SELECT max (rowid) OF test00 WHERE POINT = point 'A' AND GROUP BY)

    Thanks in advance

    Ananda.

    Something like this->

    SCOTT>
    SCOTT>select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    
    Elapsed: 00:00:00.04
    SCOTT>
    SCOTT>
    SCOTT>create table ananda
      2  as
      3    (
      4       select 1001 EMPID, 'A' N_AME, 'MACH1' CITY from dual
      5       union all
      6       select 1001, 'A', 'MACH2' from dual
      7       union all
      8       select 1002, 'B', 'MAH1' from dual
      9       union all
     10       select 1002, 'C', 'MAH1' from dual
     11       union all
     12       select 1002, 'A', 'MAH1' from dual
     13       union all
     14       select 1003, 'X', 'MACH12' from dual
     15       union all
     16       select 1003, 'X', 'MACH1' from dual
     17    );
    
    Table created.
    
    Elapsed: 00:00:00.18
    SCOTT>
    SCOTT>
    SCOTT>select * from ananda;
    
         EMPID N CITY
    ---------- - ------
          1001 A MACH1
          1001 A MACH2
          1002 B MAH1
          1002 C MAH1
          1002 A MAH1
          1003 X MACH12
          1003 X MACH1
    
    7 rows selected.
    
    Elapsed: 00:00:00.09
    SCOTT>
    SCOTT>
    SCOTT>delete from ananda
      2  where city = 'MAH1'
      3  and   rowid NOT IN (
      4                        select rr
      5                        from (
      6                                select rowid rr,
      7                                      empid,
      8                                      n_ame,
      9                                      city,
     10                                      row_number() over(partition by city order by empid) rn
     11                                from ananda
     12                                where city = 'MAH1'
     13                            )
     14                        where rn =1
     15                  );
    
    2 rows deleted.
    
    Elapsed: 00:00:00.10
    SCOTT>
    SCOTT>select * from ananda;
    
         EMPID N CITY
    ---------- - ------
          1001 A MACH1
          1001 A MACH2
          1002 B MAH1
          1003 X MACH12
          1003 X MACH1
    
    Elapsed: 00:00:00.09
    SCOTT>
    

    Kind regards.

    LOULOU.

  • WebVPN mapping of group policy-based user name not LDAP Group?

    Hi guys,.

    As the title says I'm looking for a way to map users who authenticate via LDAP to the webvpn to a particular group policy.

    The reason why I want to do, is to assign particular cifs on a per user basis. I know that you can map a LDAP group to group policy, but all users are in the same group. (I can't change that fact).

    So I was wondering if there is a way to map a "username", which authenticates via LDAP on group policy?

    Cheers.

    That's maybe what you are looking for:

    http://www.Cisco.com/en/us/products/ps6120/products_configuration_example09186a008089149d.shtml

    It is similar to the use of RADIUS 25 attribute, but for LDAP.  Read it carefully and you should find the solution.

    Please evaluate the useful messages.

  • PL/SQL insert based on conditions

    I'd appreciate any help I can get. I learn PL/SQL and have stumbled upon a problem, so please help me to find an appropriate way to deal with this situation I am running Oracle 11 GR 2

    My diagram:

    CREATE TABLE "ENTRY"
    (
    'TYPE' VARCHAR2 (5 CHAR) ,
    'TRANSACTION' VARCHAR2()5 TANK),
    'OWNER' VARCHAR2 (5 CHAR)
    ); 

    CREATE TABLE "VIEW"
    (
    'TYPE' VARCHAR2 (5 CHAR) ,
    'TRANSACTION' VARCHAR2 (5 CHAR),
    'OWNER' VARCHAR2 (5 CHAR)
    ); 

    CREATE TABLE "REJECTED"
    (
    'TYPE' VARCHAR2 (5 CHAR) ,
    'TRANSACTION' VARCHAR2 (5 CHAR),
    'OWNER' VARCHAR2 (5 CHAR)
    );

    My sample data:

    insert into entry (type, transaction, owner) values (11111, 11111, 11111);
    insert into entry (type, transaction, owner) values (22222, 22222, 22222);

    Now for the confusing part, I wrote this procedure which has to copy the values from the table ENTRY in the table VIEW if a record is no specific combination (transaction AND owner). If such an association exists in the table for VIEW this record should then go to the REJECTED table. This procedure done that but on the executions of the procedure, I get more entries in the REJECTED table so my question is how do to limit inserts them into the table of REJECTED - if a record already exists in the REJECTED table then do nothing.

    create or replace PROCEDURE COPY AS 
    v_owner_entry ENTRY
    .owner%TYPE;
    v_transaction_entry ENTRY
    .transaction%TYPE; 
    v_owner
    VIEW.owner%TYPE;
    v_transaction
    VIEW.transaction%TYPE; 

    begin 

    begin 
    select e.owner, e.transaction, v.owner, v.transaction
    into v_owner_entry, v_transaction_entry, v_owner, v_transaction
    from entry e, view v
    where e.owner = v.owner and e.transaction = v.transaction; 


    EXCEPTION
    when too_many_rows
    then insert into REJECTED ( TYPE, TRANSACTION, OWNER ) SELECT s1.TYPE, s1.TRANSACTION, s1.OWNER FROM ENTRY s1; 

    when no_data_found THEN  insert into VIEW ( TYPE, TRANSACTION, OWNER ) SELECT s.TYPE, s.TRANSACTION, s.OWNER FROM ENTRY s; 
    end;
    end;

    Any suggestions guys?

    See you soon!

    UPDATE

    Sorry if the original message was not enough - clear the procedure must replicate data (on a daily basis) of DB1 to DB2 and insert in the VIEW or REJECTED depending on the conditions. Here is a picture, it would be perhaps more clearly:

    replicate.jpg

    Hello

    your procedure could look something like this:

    declare
      -- Local variables here
      i integer;
    begin
      -- Test statements here
      INSERT INTO REJECTED
      (TYPE, TRANSACTION, OWNER)
      SELECT ENTRY.TYPE, ENTRY.TRANSACTION, ENTRY.OWNER
        FROM ENTRY, VIEW
       WHERE ENTRY.OWNER = VIEW.OWNER
         AND ENTRY.TRANSACTION = VIEW.TRANSACTION
         AND NOT EXISTS
       (SELECT NULL
                FROM REJECTED VW2
               WHERE VW2.OWNER = ENTRY.OWNER
                 AND VW2.TRANSACTION = ENTRY.TRANSACTION);
    
    INSERT INTO VIEW
      (TYPE, TRANSACTION, OWNER)
      SELECT TYPE, TRANSACTION, OWNER
        FROM ENTRY
       WHERE NOT EXISTS (SELECT NULL
                FROM VIEW
               WHERE ENTRY.OWNER = VIEW.OWNER
                 AND ENTRY.TRANSACTION = VIEW.TRANSACTION);
    COMMIT;
    end;
    

    Edited: Use SQL syntax

  • display value based on condition

    Hi all

    Do not know if my subject is the most descriptive, but don't know how to explain in a sentence.

    I have wells that may have several statutes (one record for each State). I need to create a column to display a Y or N from or not a given wells has only certain articles types. If all the records of a given good Susp or Abd, so I want to display a Y. If good records include Susp or Abd, but also the other articles (or do not even have a status of susp or abd) so I want to display a N.

    So:
    Well           Status       ident
    12345         SUSP          Y
    12345         SUSP          Y
    12345         ABD           Y
    98765         SUSP          N
    98765         PROD         N
    98765         ABD           N 
    45678         SUSP          Y
    45678         SUSP          Y
    ASDFG         ABD           Y
    ASDEG         ABD           Y
    TTTTT         PROD       N
    TTTTT         TEMP       N
    Any thoughts?

    Published by: dgouin on December 13, 2012 06:59

    Hello

    Here's one way:

    SELECT     well, status
    ,     CASE
             WHEN  EXISTS (
                              SELECT  1
                        FROM    table_x
                        WHERE   well     = m.well
                        AND     NVL ( status
                                        , '?'
                              )     NOT IN ('SUSP', 'ABD')
                          )
             THEN  'N'
             ELSE  'Y'
         END     AS ident
    FROM     table_x  m
    ;
    

    Another way uses analytical functions:

    SELECT     well, status
    ,     MIN ( CASE
                   WHEN  status IN 'SUSP', 'ABD')
                THEN  'Y'
                ELSE  'N'
               END
             ) OVER (PARTITION BY well)     AS ident
    FROM     table_x
    ;
    

    This 2nd request is based on the fact that "n" comes before "Y" is sort of chain order. If you use other symbols, such as 'J' and ' n ", then you may need to use MAX instead of MIN above."

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • Restrict the records in the CSV, based on condition

    Greetings. I searched the forum for my problem and have not found an answer or the right search terms. I'm under APEX 4.1.1

    I have a report on a page. I show all the records to a SQL query given in my table, but in the 'export to CSV' I need limit the output based on one of the fields. Thus, for example, if I had a report such as:

    SELECT x, y, Z
    FROM Table1

    I would like to export to CSV format for this table to limit the output such as:

    SELECT x, y, Z
    FROM Table1
    WHERE Z = 1

    Is this possible?

    Thank you!
    John

    Hi John,.

    I tested the connection now and works above for interactive report only and for the classic report, you need to do something like that because the demand is set to a different value

    SELECT x, y, Z
    FROM Table1
    WHERE ((Z = 1 and nvl(:REQUEST,'X') like 'FLOW_EXCEL_OUTPUT%') OR nvl(:REQUEST,'X') not like 'FLOW_EXCEL_OUTPUT%')
    

    See this example of work http://apex.oracle.com/pls/apex/f?p=46417:25

    When you export to CSV you'll get 10 dept records

  • ItemStyle by hyperlink or link without hyperlink based on condition

    OFA dear gurus,.

    I need as I need to display a field with an itemstyle as a link.

    But the field should be displayed with a hyperlink or a hyperlink under certain conditions.

    How can this be achieved?

    Can we define this hyperlink itself bean link dynamically?

    Please let me know.

    Kind regards
    Magesh.M.K.

    Mamoudou,

    Create two objects) 1 2) Message text style link

    Join two different transient attribute with the two above. And set to true & false accordingly.

    Kind regards
    GYAN

Maybe you are looking for

  • Yoga 900 - battery plugged in, does not support.

    Hello I seem to have a 'No load' intermittent problem on my Lenovo Yoga 900. This happens often when it is fully charged and I unplug for a few minutes and then plug it in again. If I let it go below 93 to 95% it will tell usually "plugged in, chargi

  • Windows XP can be updated to use all the RAM on a PC?

    Hi all I have a question that concerns me for centuries. Then Windows XP updated so that it can use all the RAM on a PC? The reason why I ask this is that I find a bit strange that my custom PC has a total of 8GBs of RAM but XP only can use a 2.96GBs

  • Need help get the dvd to play

    Can a cd & dvd play on my D: drive?  If Yes, what should I do to make this happed? Currently, both D & E: drives say cd: drive.no mention of dvd player.

  • Need help with 6 33 sidebyside event log error questions

    I did a complete reinstall of Windows Vista.  The event log showed mistakes aside nearby.   This is one of the six - sxstrace.exe used for the information: Launch the activation context generation.Input parameter:Flags = 0ProcessorArchitecture = AMD6

  • Does anyone know how I could free more space/add more space to my backup drive?

    Original title: save file/disk Dear all, As usual, I used part of my hard drive to back up files, etc. In my last scheduled backup, windows informed me that he could not perform the cause there wasn't enough space in my backup disk. Does anyone know