writing a simple query

Hello dear friends,

I have the table below, for the State of the field, if 0 it means that the liabilities and if 1 this means active.

I want to write a query to return users who have more active than passive users users.

I wrote this query, it is not complete and also syntax does not, correct

you would he rewrite please for me?

for current data, I want to have 2 and 3 as a result. (means the User2 and user3)

Oracle 11g.

{code}

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

-Datei standing - Freitag-February-28-2014

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

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

-The DOF for Table FRIEND

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

CREATE TABLE FRIEND

('FRIEND1' NUMBER,

'FRIEND2' NUMBER,

NUMBER OF the 'STATE '.

) CREATION OF IMMEDIATE SEGMENT

PCTFREE, PCTUSED, INITRANS 40 10 1 MAXTRANS 255

REGISTRATION OF NOCOMPRESS

STORAGE (INITIAL 57344 NEXT 57344 MINEXTENTS 1 MAXEXTENTS 2147483645)

PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1

USER_TABLES FLASH_CACHE, CELL_FLASH_CACHE DEFAULT DEFAULT)

TABLESPACE "STUDENT";

REM, INSERTING a FRIEND

TOGETHER TO DEFINE

Insert in a FRIEND (FRIEND1, FRIEND2, STATE) values ('1', ' 1', ' 0');

Insert in a FRIEND (FRIEND1, FRIEND2, STATE) values ('2', ' 3', 1');

Insert in a FRIEND (FRIEND1, FRIEND2, STATE) values ('3', ' 2', 1');

Insert in a FRIEND (FRIEND1, FRIEND2, STATE) values ('4', ' 5', ' 0');

Insert in a FRIEND (FRIEND1, FRIEND2, STATE) values ('3', ' 4', 1');

{/ code}

{code}

Select f1. FRIEND1 to f1, f2 friend friend where

(select count (*) in the f1 where f1.friend1 <>f1.friend2 and status = 1 f1.friend1 group) > (select count (*) f2 where f2.friend1 f2.friend2 and status = <>group by f2.friend1 0)

and f1.friend1 = f2.friend1;

{/ code}

Thank you in advance.

Hello

Of course; everything you can do with DECODE, you can also do business (and vice versa):

SELECT friend1

DE)

SELECT friend1, friend2, State

Friend

UNION - or UNION ALL

SELECT friend2, friend1, State

Friend

)

GROUP BY friend1

SEEN THE SUM (CASE

WHEN the State = 0

THEN-1

1. OTHER

END

) > 0

;

What is the problem with DECODE?  What problem are you trying to solve avoiding DECODE them?  Always explain why you want to do something; otherwise, you might get a solution that does what you requested, but does not solve your problem.

Is this just because the DECODING is so enigmatic: difficult to understand and so easy to get wrong?  It's a good reason.  This is why I almost never use DECODE; I almost always use the CASE instead.  In certain situations, DECODE can be a little shorter, so, sometimes in a very complicated expressions I think DECODE is a little clearer, but this does not happen often.

Tags: Database

Similar Questions

  • A simple query with as wrong return result

    Hello

    I run a simple query with like.
    If I use the parameter I get incorrect results.
    If I use the request without parameter results are ok.

    My script:

    ALTER SESSION SET NLS_SORT = BINARY_CI;
    ALTER SESSION SET NLS_COMP = LINGUISTIC;

    -drop table abcd;
    create table abcd (col1 varchar2 (10));

    INSERT INTO VALUES ABCD ('122222');
    insert into abcd values ('111222');


    SELECT * FROM ABCD WHERE COL1 LIKE: 1. -bad result with 12%
    /*
    COL1
    ----------
    122222
    * 111222 *.
    */

    "Select * ABCD where col1 like 12%; -result ok
    /*
    COL1
    ----------
    122222
    */

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
    and query, run in Oracle SQL Developer 3.1.07.

    I think it's just a bug, and it is set to 11.2.0.3:

    11.2.0.1:

    DB11.2.0.1>> select * from v$version where rownum=1;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    
    1 row selected.
    
    DB11.2.0.1>> ALTER SESSION SET NLS_SORT=BINARY_CI;
    
    Session altered.
    
    DB11.2.0.1>> ALTER SESSION SET NLS_COMP=LINGUISTIC;
    
    Session altered.
    
    DB11.2.0.1>> create table abcd (col1 varchar2(10));
    
    Table created.
    
    DB11.2.0.1>> INSERT INTO ABCD VALUES ('122222');
    
    1 row created.
    
    DB11.2.0.1>> insert into abcd values ('111222');
    
    1 row created.
    
    DB11.2.0.1>> VARIABLE A1 VARCHAR2(10);
    DB11.2.0.1>> EXEC :A1 := '12%';
    
    PL/SQL procedure successfully completed.
    
    DB11.2.0.1>> SELECT * FROM ABCD WHERE COL1 LIKE :A1;
    
    COL1
    ----------
    122222
    111222
    
    2 rows selected.
    

    11.2.0.3:

    DB11.2.0.3>> select * from v$version where rownum=1;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    
    1 row selected.
    
    DB11.2.0.3>> ALTER SESSION SET NLS_SORT=BINARY_CI;
    
    Session altered.
    
    DB11.2.0.3>> ALTER SESSION SET NLS_COMP=LINGUISTIC;
    
    Session altered.
    
    DB11.2.0.3>> create table abcd (col1 varchar2(10));
    
    Table created.
    
    DB11.2.0.3>> INSERT INTO ABCD VALUES ('122222');
    
    1 row created.
    
    DB11.2.0.3>> insert into abcd values ('111222');
    
    1 row created.
    
    DB11.2.0.3>> VARIABLE A1 VARCHAR2(10);
    DB11.2.0.3>> EXEC :A1 := '12%';
    
    PL/SQL procedure successfully completed.
    
    DB11.2.0.3>> SELECT * FROM ABCD WHERE COL1 LIKE :A1;
    
    COL1
    ----------
    122222
    
    1 row selected.
    

    Kind regards
    Sayan Malakshinov
    http://orasql.org

  • Not sure if I can do this with a simple query.

    CREATE TABLE primary_table (SSN VARCHAR2 (15) VARCHAR2 (30) FIRST_NAME, LAST_NAME VARCHAR2 (30), VARCHAR2 (20)) of the STATE;

    insert into primary_table VALUES ('111-11-1111, 'Elvis', 'Presley', 'ACTIVE');
    insert into primary_table VALUES (222-22-2222', 'Gift', 'King', 'ACTIVE');
    insert into primary_table VALUES ('33-333-3333, 'Lex', 'Harrison', 'ACTIVE');

    CREATE TABLE secondary_table (SSN VARCHAR2 (15) NOT NULL, ARRIVAL DATE, NUMBER of LENGTH_OF_STAY);

    insert into secondary_table VALUES ('11-111-1111 ", 1 January 2011", 10);
    insert into secondary_table VALUES (' ' 222-22-2222 ", March 1, 2011", 10);
    insert into secondary_table VALUES (' ' 222-22-2222 ", June 1, 2011", 20);
    insert into secondary_table VALUES ('' 33-333-3333, January 1, 2011 ", 10);

    ========================================================================================

    Hello

    I created two very simple tables for this exercise. I don't know if I can do this with a simple query, or must use pl/sql.

    I want to join primary_table secondary_table of SSNand list the fields of primary_table, but only if the join returns only a line.

    In other words, I would like to create a list of data primary_table for primary_table lines that have only one line on the secondary table.


    Concerning

    RF25 wrote:
    CREATE TABLE primary_table (SSN VARCHAR2 (15) VARCHAR2 (30) FIRST_NAME, LAST_NAME VARCHAR2 (30), VARCHAR2 (20)) of the STATE;

    insert into primary_table VALUES ('111-11-1111, 'Elvis', 'Presley', 'ACTIVE');
    insert into primary_table VALUES (222-22-2222', 'Gift', 'King', 'ACTIVE');
    insert into primary_table VALUES ('33-333-3333, 'Lex', 'Harrison', 'ACTIVE');

    CREATE TABLE secondary_table (SSN VARCHAR2 (15) NOT NULL, ARRIVAL DATE, NUMBER of LENGTH_OF_STAY);

    insert into secondary_table VALUES ('11-111-1111 ", 1 January 2011", 10);
    insert into secondary_table VALUES (' ' 222-22-2222 ", March 1, 2011", 10);
    insert into secondary_table VALUES (' ' 222-22-2222 ", June 1, 2011", 20);
    insert into secondary_table VALUES ('' 33-333-3333, January 1, 2011 ", 10);

    ========================================================================================

    Hello

    I created two very simple tables for this exercise. I don't know if I can do this with a simple query, or must use pl/sql.

    I want to join primary_table to secondary_table of NSSand the list of fields in the primary_table, but only if the join returns only a line.

    In other words, I would like to create a list of data primary_table for primary_table lines that have only one line on the secondary table.

    Concerning

    Something like...

    select p.
    from primary_table p
    where p.ssn in (select s.ssn from secondary_table s group by s.ssn having count(*) = 1)
    
  • Problem with a simple query

    Hello, I'll start by saying that I am a noob. in any case, I'm trying to do what I thought was a simple query for records that are greater or equal to the date of the day: it's my request...

    < cfquery name = "getUpcoming" datasource = 'events' >
    SELECT title, eventDate FROM event WHERE eventDate > = #Now () # ORDER BY ASC eventDate
    < / cfquery >

    It works, so, I get the records that are greater than the current date, but all records that match to are not.

    I guess that it is looking at the time as well, or should I completely wrong. I do not know? Any help would be greatly appreciated.

    Good reading up on top of (http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f 6f.html), which you must use when you pass dynamic values to the DB, instead of hard-coding the in your SQL string.  And when using , use a param of CF_SQL_DATE type, and must ignore the time portion of the date/time value, you pass (I'm not 100% certain of this... only about 99% certain... but give it a go).  Or spend only the date part of the date/time value in the query.  Using createOdbcDate() fact, without all the extra horsing around adding things together and using the dateFormat() attribute as the previous poster suggested.

    --

    Adam

  • Improve a simple query

    Here's a simple query, what I want to know, I added superior select d.name, which is the description of region_code for. Can I get a whole result with a single statement select

    SELECT t.region_code, d.name, t.emp_contr
    Of
    (SELECT c.br_region_fo_code as Region_Code,
    Sum (c.employer_contribution) AS emp_contr
    OF core_business.cb_contr_emp_pmt_slip c
    T GROUP BY c.br_region_fo_code),
    general_information.cb_region_fo d
    WHERE t.br_region_fo_code = d.region_fo_code;

    Try this:

    SELECT c.br_region_fo_code as Region_Code,
               d.name,
               SUM(c.employer_contribution) OVER(PARTITION BY  c.br_region_fo_code ORDER BY c.br_region_fo_code) AS emp_contr
    FROM   core_business.cb_contr_emp_pmt_slip c,
               general_information.cb_region_fo d
    WHERE
               c.br_region_fo_code = d.region_fo_code;
    
  • Simple query in Oracle Table in MS Access causes a full table scan.

    I run a very simple query in MS ACCESS to an Oracle table attached as follows:

    Select *.
    EXPRESS_SERVICE_EVENTS-(EXPRESS is the name of the related table. SERVICE_EVENTS)
    When executed > MyDate()

    or

    Select *.
    EXPRESS_SERVICE_EVENTS-(EXPRESS is the name of the related table. SERVICE_EVENTS)
    When executed > [Forms]! [MyForm]! [Date1]

    We have more than 50 machines and this query works well on more than half of them, using an Oracle Index on the field "run." Exactly the same thing running on other machines results in a full table scan, so regardless of the index (the DB access even access all machines).

    Strangely, if we write the query as follows:

    Select *.
    Of EXPRESS_SERVICE_EVENTS
    When executed > # 2009-09-04 08:00 #.

    It works fast everywhere!

    Any help with this "phenominon" would be appreciated.

    We did the things:
    Check the locale settings of the ODBC driver, MS Access settings (as in tools-> Options), we have the latest XP and Office service packs and re-related all the Access Tables on the slow and fast machines independently).

    All machines use the same version of the ODBC driver?

    If you have access to Metalink, check the following note:
    Note.257828.1 Scan of Table full Ext/Pub while seeking the DATE columns using the ODBC Oracle driver:

    In a Word, try "bind timestamp date" option in the dsn configuration and do not forget to update the links in the table.

    It will be useful,
    Greg

  • Choice of the message can be changed in the table of search results Simple query region?

    Hi friends,

    I have a Simple search query region in 11i.

    I created the SearchVO and bound to the query Table Region.

    I have two attributes MessageStyleText and a MessageChoice attribute in the simple search criteria.

    Search results show very well for all attributes.

    But when I search with the criteria of MessageChoice, in the table of results, this attribute MessageChoice is indicated as editable, display the drop-down list.

    I did this attribute ReadOnly = True but then it becomes readonly in search also. So this dosent help.

    I need to this drop-down list of MessageChoice be modifiable in the search criteria, but read in the table of results.

    Please help me with the resolution. Its kinda urgent.

    Would appreciate any help.

    Thank you

    Rajesh

    He solved.

    Added programmatically in code.

    Kept the attribute as MessageChoice in the query Table Region.

    Added to the controller

    ' Public Sub processRequest (pageContext OAPageContext, OAWebBean webBean)

    {

    super.processRequest (pageContext, webBean);

    OAM OAApplicationModule = pageContext.getRootApplicationModule ();

    OAMessageChoiceBean = processFlagMessageChoice

    (OAMessageChoiceBean) webBean.findChildRecursive ("AttributeId");

    processFlagMessageChoice.setReadOnly (true);

    }

  • simple query... but could not

    CREATE TABLE person_del
    (
    DNO VARCHAR2 (5).
    place VARCHAR2 (10),
    EU VARCHAR2 (10)
    )

    commit;

    insert into person_del values('1','home','Y')

    insert into person_del values('1','office','N')

    insert into person_del values('1','other','Y')

    insert into person_del values('2','office','Y')

    insert into person_del values ('3', 'home', 'n')

    insert into person_del values ('3 ', 'Office', 'Y')

    insert into person_del values ('4 ', 'other', 'n')

    insert into person_del values ('5', 'home', 'Y')

    insert into person_del values ('6', 'home', 'n')

    insert into person_del values ('6', 'Office', 'n')

    insert into person_del values ('7', 'home', 'Y')

    insert into person_del values ('7 ', 'Office', 'Y')

    commit;

    Select * from person_del

    Select the dno, place, got,
    -case when am = 'Y', and then 'Y '.
    Another null
    end as "won".
    of person_del
    where to put in ("home", "office")


    I ran the query above, but the result is not what I wanted
    The condition is as follows:
    List Y in a new column "earned" for these dno who reached the place - home or office
    If a = Y for the home place and GOT = N for the Office of the place, then only view this column where OBTAINED = Y
    If a = N to the home place and GOT = Y for the Office of the place, and then view only this column where OBTAINED = Y
    If both are N then list a any column
    If the two are then all a fo the column in the list
    The place else is not taken into account
    The output should be dno and won the column

    I know it's simple... but I couldn't do it and I need it in a few minutes
    Can someone help me on this using the CASE statement or something that is not difficult to understand the ASAP?

    Basically, the output of it should be as follows:

    DNO has won
    1. IS
    3 8
    2 8
    8 4
    6 N
    7. THERE

    What:

    SQL> select dno
      2  ,      got won
      3  from ( select dno
      4         ,      got
      5         ,      row_number() over (partition by dno, got order by dno, got desc) cnt
      6         from   person_del t
      7         where  t.place in ('home', 'office')
      8       )
      9  where ( case
     10            when got = 'Y' and cnt = 1 then 1
     11            when got = 'N' and cnt = 2 then 1
     12          end
     13        ) = 1;
    
    DNO   WON
    ----- ----------
    1     Y
    2     Y
    3     Y
    5     Y
    6     N
    7     Y
    
    6 rows selected.
    
  • Why XML XML Simple query on Table Eval does not work?

    I have a request that a simple select on a binary xml table on 11.2.0.1:
    SELECT xmlcast(xmlquery('$p/eval/@evalId' passing e.object_value AS "p" RETURNING CONTENT)
    AS VARCHAR2(30)) "EVAL ID"
    FROM eval e
    WHERE xmlexists('declare default element namespace "http://www.cigna.com/acme/domains/eval/2010/03";
    /eval[@evalId=$eval_id]' PASSING object_value, 'RickBlanchard9972' as "eval_id");
    Now this xml document exists as a record in the binary xml table with evalId = "RickBlanchard9972" attribute
    <?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?><eval createdById="1957" acmeMemberId="37e6f05a-88dc-41e9-a8df-2a2ac6d822c9" category="external" eval_dt="2012-02-11T23:47:02.645Z" evalId="RickBlanchard9963" xmlns="http://www.cigna.com/acme/domains/eval/2010/03" xmlns:ns2="http://www.cigna.com/acme/domains/derived/fact/2010/03" xmlns:ns3="http://www.cigna.com/acme/domains/common/2010/03">
       <derivedFacts>
          <ns2:derivedFact>
             <ns2:defId>888</ns2:defId>
             <ns2:defUrn>urn:coderunner:Medical:Definition:DerivedFact:52600:2</ns2:defUrn>
             <ns2:factSource>CCDR Member</ns2:factSource>
             <ns2:origInferred_dt>2012-02-11T23:47:02.645Z</ns2:origInferred_dt>
             <ns2:factValue>
                <ns2:type>string</ns2:type>
                <ns2:value>null</ns2:value>
             </ns2:factValue>
          </ns2:derivedFact>
          <ns2:derivedFact>
             <ns2:defId>777</ns2:defId>
             <ns2:defUrn>urn:coderunner:Medical:Definition:DerivedFact:52599:1</ns2:defUrn>
             <ns2:factSource>CCDR Member</ns2:factSource>
             <ns2:origInferred_dt>2012-02-11T23:47:02.645Z</ns2:origInferred_dt>
             <ns2:factValue>
                <ns2:type>string</ns2:type>
                <ns2:value>INT</ns2:value>
             </ns2:factValue>
          </ns2:derivedFact>
          <ns2:derivedFact>
             <ns2:defId>666</ns2:defId>
             <ns2:defUrn>urn:coderunner:Medical:Definition:DerivedFact:51400:1</ns2:defUrn>
             <ns2:factSource>CCDR Member</ns2:factSource>
             <ns2:origInferred_dt>2012-02-11T23:47:02.645Z</ns2:origInferred_dt>
             <ns2:factValue>
                <ns2:type>integer</ns2:type>
                <ns2:value>32</ns2:value>
             </ns2:factValue>
          </ns2:derivedFact>
          <ns2:derivedFact>
             <ns2:defId>555</ns2:defId>
             <ns2:defUrn>urn:coderunner:Medical:Definition:DerivedFact:52177:3</ns2:defUrn>
             <ns2:factSource>CCDR Member</ns2:factSource>
             <ns2:origInferred_dt>2012-02-11T23:47:02.645Z</ns2:origInferred_dt>
             <ns2:factValue>
                <ns2:type>string</ns2:type>
                <ns2:value>null</ns2:value>
             </ns2:factValue>
          </ns2:derivedFact>
          <ns2:derivedFact>
             <ns2:defId>444</ns2:defId>
             <ns2:defUrn>urn:coderunner:Medical:Definition:DerivedFact:52075:1</ns2:defUrn>
             <ns2:factSource>CCDR Member</ns2:factSource>
             <ns2:origInferred_dt>2012-02-11T23:47:02.645Z</ns2:origInferred_dt>
             <ns2:factValue>
                <ns2:type>string</ns2:type>
                <ns2:value>F</ns2:value>
             </ns2:factValue>
          </ns2:derivedFact>
          <ns2:derivedFact>
             <ns2:defId>333</ns2:defId>
             <ns2:defUrn>urn:coderunner:Medical:Definition:DerivedFact:51392:1</ns2:defUrn>
             <ns2:factSource>CCDR Member</ns2:factSource>
             <ns2:origInferred_dt>2012-02-11T23:47:02.645Z</ns2:origInferred_dt>
             <ns2:factValue>
                <ns2:type>boolean</ns2:type>
                <ns2:value>true</ns2:value>
             </ns2:factValue>
          </ns2:derivedFact>
          <ns2:derivedFact>
             <ns2:defId>222</ns2:defId>
             <ns2:defUrn>urn:coderunner:Medical:Definition:DerivedFact:52837:2</ns2:defUrn>
             <ns2:factSource>CCDR CaseManagement</ns2:factSource>
             <ns2:origInferred_dt>2012-02-11T23:47:02.645Z</ns2:origInferred_dt>
             <ns2:factValue>
                <ns2:type>boolean</ns2:type>
                <ns2:value>true</ns2:value>
             </ns2:factValue>
          </ns2:derivedFact>
       </derivedFacts>
    </eval>
    Unfortunately, the query returns with a null value instead of; RickBlanchard9963


    Must be something obvious missing here...
    Any help is appreciated.

    Kind regards
    Rick Blanchard

    The sample document contains evalId = "RickBlanchard9963", not "RickBlanchard9972" but it's probably a typo?

    The real problem is that you are missing from the default namespace declaration in XMLQuery.

  • How to make the simple query for this scenario... ?

    Hello:

    Dummy table provided for simplicity.

    It's my database table (Table_A)

    Date1 | Plane1 | Category | Duration | Fees
    01/01/2011 | A | Gold | 5. 2
    01/01/2011 | C | Money | 4. 11
    01/01/2011 | B | Gold | 6. 2
    01/01/2011 | D | Gold | 2. 4
    01/01/2011 | B | Gold | 3. 5
    01/01/2011 | A | Money | 4. 8
    01/01/2011 | B | Gold | 1. 3

    I need to write a query to get the result below:

    Date1 | Plane1 | Sum_Duration | Sum_Charge | Sum_Gold_Duration | Sum_Gold_Charge | Sum_Silver_Duration | Sum_Silver_Charge
    01/01/2011 | A | 9. 10. 5. 2. 4. 8
    01/01/2011 | B | 10. 10. 10. 10. 0 | 0
    01/01/2011 | C | 4. 11. 0 | 0 | 4. 11
    01/01/2011 | D | 2. 4. 2. 4. 0 | 0

    This query will provide the 1st four columns:

    SELECT Date1,
    base1,
    Sum (Duration) Sum_Duration,
    Sum (load) Sum_Charge
    FROM TABLE_A
    GROUP BY date1, rarateplan

    But I need to know how to get the rest of the columns (i.e. Summary according to categories; from 5 to 8 columns)? Is this can be done in a single query without writing subqueries?

    Please let me know, (with code), the best way.

    Thank you-
    Tanvir

    Use like this:

    SELECT Date1,
    base1,
    Sum (Duration) Sum_Duration,
    Sum (load) Sum_Charge,
    SUM (decode(Category,'Gold',duration,0)) Sum_Gold_Duration,
    SUM (decode(Category,'Gold',charge,0)) Sum_Gold_charge,
    SUM (decode(Category,'Silver',duration,0)) Sum_Silver_Duration,
    SUM (decode(Category,'Silver',charge,0)) Sum_Silver_charge
    FROM TABLE_A
    GROUP BY date1, rarateplan

    Published by: SANT007 on August 11, 2011 11:04

  • The simple query help

    Hello! I have a simple request: NO of ROAD_TYPE = "RAMP" or NO FUNC_CODE = 7 FUNC_CODE or NOT = 0 or NOT FUNC_CODE = NULL, each element of the query by itself without problem, tracks, but linked together in this way with the GOLD, one of them opts on. What I am doing wrong?

    It's the difference between OR and and.

    Think about this simple example

    Where Column != A or Column != B.
    

    Excluding the Null handling, it's true. Because for the first condition, it will be true for all but one, and the second condition will be true for A. You need an AND, not a RC.

    For simplicity and readability without doubt, use an In operator, and group together them. It would therefore be:

    Where Road_Type != 'RAMP' and Func_Code Not In('0, 7) and Func_Code is not Null
    
  • Cannot get this simple query!

    Hi guys,.

    There is this requirement easy to write a query that selects many columns in a table, but grouped on 3 columns in the same table.

    Table Str:
    C11 col2 col3 col4 col5 col6 col7 col8 col9 col10

    Mandatory:
    Group By: Col9, col10
    Columns to select: C11 col2 col3 col4 col5 col6 col7 col8

    I know there is something simple that I'm missing.

    any help will be appreciated.

    Thank you!

    Hello

    What produces the output you asked for the data that you have posted:

    SELECT       MIN (col1)
    ,       MIN (col2)
    ,       MIN (col3)
    ,       MIN (col4)
    ,       MIN (col5)
    ,       MIN (col6)
    ,       MIN (col7)
    ,       MIN (col8)
    ,       col9
    ,       col10
    FROM       str
    GROUP BY  col9
    ,       col10
    ;
    

    If the fact

    WITH     got_rnum     AS
    (
         SELECT  str.*
         ,     ROW_NUMBER () OVER ( PARTITION BY  col9
                             ,             col10
                             ORDER BY        col1
                             ,             col2
                             ,             col3
                             ,             col4
                             ,             col5
                             ,             col6
                             ,             col7
                             ,             col8
                             )     AS rnum
         FROM     str
    )
    SELECT     col1
    ,     col2
    ,     col3
    ,     col4
    ,     col5
    ,     col6
    ,     col7
    ,     col8
    ,     col9
    ,     col10
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    

    With the sample data that you posted both queries produce the same results.
    With other data, both queries will produce different results.

  • How to write this Simple query?

    Select * from student

    where

    (select count (first_name) of student) > 1;

    Basically I want a list of student table where the counties of first names are more than 1. However he shows me the output for

    Select * from student;

    any suggestions?

    Hello

    2776946 wrote:

    Select * from student

    where

    (select count (first_name) of student) > 1;

    Basically I want a list of student table where the counties of first names are more than 1. However he shows me the output for

    Select * from student;

    any suggestions?

    Think about it.  The subquery tells you the number of rows in all of the table have a first name.  It will always tell you the number of rows in all of the table name.  You don't want to know how many rows in the table have a name, you want to know how many rows in the table have the same name.

    One way to do is a correlated subquery:

    Select *.

    student m-m is for hand query

    where)

    SELECT count (*)

    student s-s is for the subquery

              where s.first_name = m.first_name

    )  > 1

    ;

  • REGEXP_SUBSTR simple query

    Hi all

    Select RTRIM (REGEXP_SUBSTR('675809532|11787148|0','[a-zA-Z0-9]+\|'),'| ') double cardid

    Output

    --------

    675809532

    form above query I had the first value 675809532 how can I second valueor third value only pls help for these

    I need to pass the value to the variable individally

    Thank you...

    By adding the occurece to the RegExp as:

    Select RTRIM (REGEXP_SUBSTR ("675809532 |")) 11787148 | 0','[a-zA-Z0-9] + \| ?', 1,2),'| ') the double cardid

    and the regular expression would be easier that way:

    Select REGEXP_SUBSTR ('675809532 | 11787148 | 0', ' [^ \ |] +' 1, 3) double cardid

    HTH

  • Problem with the simple query.

    Hi all

    I am facing problem with the query below

    Select A.COL1, A.COL2

    B.COL1, B.COL2

    FROM TABLE1 A

    TABLE 1 B

    WHERE A.header = '123'

    AND B.header = '123'

    AND nvl (A.COL6, 'ABC') = 'ABC '.

    AND NVL (B.COL6, 'DEF') = 'DEF '.

    Basically, my requiremenyt is: I have only one table, TABLE1 here, which has a line two lines (for the same header) as "ABC" and another is "DEF". Table 1 has two columns (col1, col2) that should be displayed for both lines.

    When the header has two records in table1 top query works. and but if I do not have a record for any header example there are a record for "abc" in col6 only. so my query above does not work because there is no record for 'DEF' in col6. But I want to again request to fecth the output (for b.col1 and b.col2 should have null values)

    could you pls suggest me how to get the 4 columns.

    Thanks in advance

    Kind regards

    UVA.

    Try to place the status of outer join on column: analytical_criterion_code as

    and nvl (AUDIT.analytical_criterion_code, 'AUDIT2') = 'verification2. '

    .

    .

    and nvl (TRANS.analytical_criterion_code, 'TRANS2') = 'TRANS2.

    In the sub query based on the opinions that you have given in post # 1, although there is no value "DEF * ' for col6 due to the condition of outer join on b.col6 (+) line is extracted with b.col [1,2,3] as NULL values. Try to remove the (+) sign b.col6 and test.

    with t as)

    Select 111 col1, col2 'aaa', 'ABC' col6 123 header of all the double union

    Select 222 'bbb', 'DEF' col6, 123 double header

    )

    q as (select 123 double header)

    Select A.COL1, A.COL2, A.COL6

    B.COL1, B.COL2, b.COL6

    q.header

    T a

    t b

    q

    where a.col6 (+) = 'ABC '.

    and b.col6 (+) = "DEF."

    and q.header = a.header (+)

    and q.header = b.header (+)

Maybe you are looking for

  • Enable Cookies for all users

    Hello I have a series of computers that run the mozilla firefox. For some reason, firefox handling cookies is disabled by default for everyone who uses a computer. I can activate on a per user basis, but it's tedious. Not to mention he's totally conf

  • HP Pavilion 500 023w: BIOHD -.

    I was everywhere except in the right place, looking for the solution. I read a lot of cases that are the same but no suggestion that work! Is there any help out there?

  • Impossible to activate the Windows Firewall - error code 0 x 80070422

    Hello This is the first time I see that the windows firewall is disabled and when I try to turn the action center it shows like below. then when I click on manual settings it shows as the second screen. I tried to install the updates from HP, but it

  • gamepad Xbox 360 are not not in Device Manager

    Hello. I've been using a controller wired xbox 360 on my laptop with windows vista 32 bit 2 days ago. It worked fine, but then I was playing and all of a sudden it disconnected and my computer no longer recognizes. Sometimes it works after that I res

  • lose sp2__randomly Windows vista 32 bit display and then turn off stops. ___can someone advise me on this?

    Event log States: Event ID: 7036 - system - Windows Image Acquisition Service entered the suspended state Event ID: 42 - Kernel-Power - system enters sleep I can easily reboot to the initial page of the web/application page by moving the mouse in the