SQL query to search for a single line

Hi All-
I have a requirement where I have to get the id who subscribe only to a single course based on data below.

ID courses
103812 CFH
102968 REP
103812 DFH
DFH 102968
103071 DFH
CFH 102968

CREATE TABLE classes
(IDENTIFICATION NUMBER,
course VARCHAR2 (3));

insert into class values (103812, "CFH");
insert into class values (102968, "REP");
insert into class values (103812, "DFH");
insert into class values (102968, "DFH");
insert into class values (103071, "DFH");
insert into class values (102968, "CFH");

SELECT THE ID
IN THE COURSE OF
GROUP BY ID
AFTER HAVING COUNT (RACE) = 1;

Tags: Database

Similar Questions

  • SQL query to search for the line that contains the identifier for each consecutive group

    Hello

    I'm on 11.2.0.3 Enterprise Edition.

    I have a strange request here - do not know if this is possible without going to procedure...

    Given these data of the sample:

    create table test_status (
      status varchar2(10),
      revision_id number,
      revision_timestamp timestamp);
    
    insert into test_status values ('PROPOSED', 1, systimestamp);
    insert into test_status values ('PROPOSED', 2, systimestamp);
    insert into test_status values ('PROPOSED', 3, systimestamp);
    insert into test_status values ('ACTIVE', 4, systimestamp);
    insert into test_status values ('ACTIVE', 5, systimestamp);
    insert into test_status values ('PROPOSED', 6, systimestamp);
    insert into test_status values ('PROPOSED', 7, systimestamp);
    insert into test_status values ('ACTIVE', 8, systimestamp);
    insert into test_status values ('ACTIVE', 9, systimestamp);
    insert into test_status values ('FINISHED', 10, systimestamp);
    insert into test_status values ('FINISHED', 11, systimestamp);
    insert into test_status values ('FINISHED', 12, systimestamp);
    

    Gives me:

    SQL> select *
      2  from test_status
      3  order by revision_id;
    
    
    STATUS     REVISION_ID REVISION_TIMESTAMP
    ---------- ----------- -----------------------------
    PROPOSED             1 25-SEP-14 04.49.47.954000 PM
    PROPOSED             2 25-SEP-14 04.49.47.962000 PM
    PROPOSED             3 25-SEP-14 04.49.47.966000 PM
    ACTIVE               4 25-SEP-14 04.49.47.969000 PM
    ACTIVE               5 25-SEP-14 04.49.47.972000 PM
    PROPOSED             6 25-SEP-14 04.49.47.976000 PM
    PROPOSED             7 25-SEP-14 04.49.47.979000 PM
    ACTIVE               8 25-SEP-14 04.49.47.982000 PM
    ACTIVE               9 25-SEP-14 04.49.47.987000 PM
    FINISHED            10 25-SEP-14 04.49.47.991000 PM
    FINISHED            11 25-SEP-14 04.49.47.996000 PM
    FINISHED            12 25-SEP-14 04.49.48.000000 PM
    
    
    12 rows selected.
    ws selected.
    

    I want to get this result:

    STATUS     REVISION_ID REVISION_TIMESTAMP
    ---------- ----------- ----------------------------
    PROPOSED             3 25-SEP-14 04.49.47.966000 PM
    ACTIVE               5 25-SEP-14 04.49.47.972000 PM
    PROPOSED             7 25-SEP-14 04.49.47.979000 PM
    ACTIVE               9 25-SEP-14 04.49.47.987000 PM
    FINISHED            12 25-SEP-14 04.49.48.000000 PM
    

    Then query the table ordered by Revision_Id, I would get the line containing the highest revision for each consecutive group of status values.  I am able to get the line containing the highest revision for each separate status, value, but I can't deal with the scenario where a state value reappears later.  In the case of the real world, it is a workflow and I need to take into account the fact that an element through the workflow may be redirected to the back front she proceeds forward again.

    Hope it makes sense.

    Thank you

    John

    Hi, John,.

    John OToole (Dublin) wrote:

    Hello

    I'm on 11.2.0.3 Enterprise Edition.

    I have a strange request here - do not know if this is possible without going to procedure...

    ...

    Do not no stinkin' procedure:

    WITH got_grp_id AS

    (

    SELECT the status, revision_id, revision_timestamp

    ROW_NUMBER () OVER (ORDER BY revision_id)

    -ROW_NUMBER () (PARTITION STATUS

    ORDER BY revision_id

    ) AS grp_id

    OF test_status

    )

    SELECT status

    MAX (revision_id) AS revision_id

    MAX (revision_timestamp) DUNGEON (DENSE_RANK LAST ORDER BY revision_id)

    AS revision_timestamp

    OF got_grp_id

    GROUP BY status, grp_id

    ORDER BY revision_id

    ;

    For an explanation of the technique of Difference sets used here, see

    Analytic Question lag and lead and/or

    Re: Ranking of queries

  • Stuck on a sql query to search for records that have the same parent child records

    Oracle 10 g 2 Enterprise Edition.

    Hello

    I'm writing a logic to find records in a parent table, who have the same values in a child table.
    This is part of a larger application, but I am stuck on that part for now, so I have mocked some of the below simplified tables to capture the heart of the
    the problem is that I'm stuck.
    Let's say I have a responsible parent, child employee table table and there are a number of many relationships between them.
    The aptly named Join_Table manages the relationship between them. If a manager can manage several employees, an employee can be managed by
    many managers.

    I have a feeling it's stupidly easy, but it seems to me having a bad episode of brain freeze today!
    -- parent table
    CREATE TABLE manager (
     id      number primary key,
     name      varchar2(100));
    
    -- child table 
    CREATE TABLE employee (
     id          number primary key,
     name      varchar2(100));
    
    -- link table
    CREATE TABLE join_table (
     manager_id          NUMBER, 
     employee_id      NUMBER,
     CONSTRAINT join_table_pk PRIMARY KEY (manager_id, employee_id),
     CONSTRAINT manager_fk FOREIGN KEY (manager_id) REFERENCES manager(id),
     CONSTRAINT employee_fk FOREIGN KEY (employee_id) REFERENCES employee(id) 
     );
    
    -- Insert some managers
    INSERT INTO manager (id, name) VALUES (1, 'John');
    INSERT INTO manager (id, name) VALUES (2, 'Bob');
    INSERT INTO manager (id, name) VALUES (3, 'Mary');
    INSERT INTO manager (id, name) VALUES (4, 'Sue');
    INSERT INTO manager (id, name) VALUES (5, 'Alan');
    INSERT INTO manager (id, name) VALUES (6, 'Mike');
    
    -- Insert some employees 
    INSERT INTO employee (id, name) VALUES (101, 'Paul');
    INSERT INTO employee (id, name) VALUES (102, 'Simon');
    INSERT INTO employee (id, name) VALUES (103, 'Ken');
    INSERT INTO employee (id, name) VALUES (104, 'Kevin');
    INSERT INTO employee (id, name) VALUES (105, 'Jack');
    INSERT INTO employee (id, name) VALUES (106, 'Jennifer');
    INSERT INTO employee (id, name) VALUES (107, 'Tim');
    
    -- Insert the links
    -- John manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 103);
    -- Bob manages Paul, Simon, Kevin, Jack
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 104);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 105);
    -- Mary manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 107);
    -- Sue manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 107);
    -- Alan manages Paul, Simon, Ken, Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 103);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 107);
    -- Mike manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 103);
    
    -- For sanity
    CREATE UNIQUE INDEX employee_name_uidx ON employee(name);
    If I ask for Manager John, so I want to find other managers who manage the exact list and even employees.
    Answer should be Mike.
    If I ask for Manager of Mary, the answer should be Sue.

    This query will give me the list of managers who manage some of the same employees as John, but not the same employees accurate...
    SELECT DISTINCT m.name AS manager
    FROM manager m, join_table jt, employee e
    WHERE m.id = jt.manager_id
    AND jt.employee_id = e.id
    AND e.id IN (
         SELECT e.id
         FROM manager m, join_table jt, employee e
         WHERE m.id = jt.manager_id
         AND jt.employee_id = e.id
         AND m.name = 'John')
    ORDER BY 1;
    I thought about using set operations to find managers with a list of employees less than my employees is null and where my employees under their list of employees is null. But there must be an easier way more elegant.
    Any ideas?
    BTW, I need to run as a batch on tables with > 20 million rows so the efficiency of queries is key.

    What about...

    WITH manager_list AS
    (
     SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
     FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id
      AND   m.name = :P_MANAGER)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    ), all_list AS
    (
     SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
     FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    )
    SELECT a.*
    FROM   manager_list m,
           all_list a
    WHERE  m.employees = a.employees
    

    Would be easier in 11g, but I do not have a facility here so this is based on 10g.

    See you soon

    Ben

  • query to search for the user of the application

    Hello

    What is the query to search for the user of the application in the sql command?

    I tried the query below
    select app_user from dual;
    app_user invalid identifier
    Thank you.

    Hello skud,
    The following SQL statement will give you the APP_USER which is an environmental variable in the APEX:

    SELECT v('APP_USER') FROM DUAL;
    

    See if it works. As I used the syntax given in the triggers to record audit trail above and it works fine.
    Kiran

    Published by: chubby Kiran June 11, 2011 04:08

    Published by: chubby Kiran June 11, 2011 04:09

  • PL/SQL muliple line insert for a single line

    I need to insert several lines in a single line. Here is the table structures and sample data
    CREATE TABLE TEST_SAMPLE (NAME VARCHAR2(20), ATTR_1 VARCHAR2(20), ATTR_2 VARCHAR2(20), ATTR_3 VARCHAR2(20),ATTR_4 VARCHAR2(20));
    
    CREATE TABLE TRANSACTION (NAME VARCHAR2(20), ATTR VARCHAR2(20))
    
    insert into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values ('hello','asd','fgh','ert',null);
    For the anecdote above in the TEST_SAMPLE table, three records must be populated\inserted in TRANSACTION table. In PL/SQL
    stored procedure I am insert records of TRANSACTIONS when ATTR_1 or ATTR_2 or ATTR_3 or ATTR_4 is not null.

    Please help me to find a better way to insert above in table TRANSACTION?

    Like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  insert all
      2    when 1=1 then
      3      into TEST_SAMPLE (NAME, ATTR_1, ATTR_2, ATTR_3,ATTR_4) values (name, attr_1, attr_2, attr_3, attr_4)
      4    when attr_1 is not null then
      5      into TRANSACTION (NAME, ATTR) values (name, attr_1)
      6    when attr_2 is not null then
      7      into TRANSACTION (NAME, ATTR) values (name, attr_2)
      8    when attr_3 is not null then
      9      into TRANSACTION (NAME, ATTR) values (name, attr_3)
     10    when attr_4 is not null then
     11      into TRANSACTION (NAME, ATTR) values (name, attr_4)
     12  select 'hello' as name
     13        ,'asd' as attr_1
     14        ,'fgh' as attr_2
     15        ,'ert' as attr_3
     16        ,null as attr_4
     17* from dual x
    SQL> /
    
    4 rows created.
    
    SQL> select * from test_sample;
    
    NAME                 ATTR_1               ATTR_2               ATTR_3               ATTR_4
    -------------------- -------------------- -------------------- -------------------- --------------------
    hello                asd                  fgh                  ert
    
    SQL> select * from transaction;
    
    NAME                 ATTR
    -------------------- --------------------
    hello                asd
    hello                fgh
    hello                ert
    
  • How can I add a spell checker this spelling laurys for a single line?

    I want a spell checker that checks my spelling for just a single line. For example, Ebay feedback is only one line long then how I spell check my typed in response? Thank you.

    You can do this by changing a hidden preference

    1. Type of topic: config in the address bar and press on enter, accept the message of warning that is displayed and you will be taken to a list of preferences
    2. In the upper search box, type out, will you limit the results to a small number of preferences
    3. Double-click the layout.spellcheckDefault preference and change its value to 2, which will allow the spell on simple lines

    See http://kb.mozillazine.org/Layout.spellcheckDefault for more details about this preference

  • SQL query returns no row vs. multiple lines

    Hello

    I am trying to get the result of a simple sql query,
    If there is no row returned, he would have "No. ROWS" in the result set.
    Other wise all the rows containing data is necessary.

    Let me know how this could be achieved. Under query works for the latter and not first case as mentioned below

    OUTPUT

    + (box 1) when we use B_ID = 123456 +.

    IDS
    -----
    'NO LINE '.

    + (box 2) when we use B_ID = 12345 +.
    IDS
    -----
    1 11112345
    2 22212345
    create table TEMP_AAA
    (
      A_ID VARCHAR2(10),
      B_ID VARCHAR2(10)
    )
    
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('111','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('222','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('333','12000');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('444','10000');
    WITH 
    MATCH_ROWS AS
    (
           SELECT A_ID||B_ID IDS FROM TEMP_AAA WHERE B_ID=12345
    ),
    
    MATCH_ROW_COUNT AS
    (
           SELECT COUNT(1) AS COUNTS FROM MATCH_ROWS
    ),
    
    PROCESSED_ROWS AS
    (
           SELECT
                 CASE WHEN COUNTS = 0
                      THEN 
                       (SELECT NVL((SELECT IDS FROM TEMP_AAA WHERE B_ID=12345),'NO ROWS') IDS FROM DUAL)
                      ELSE
                       MATCH_ROWS.IDS
                 END IDS     
            FROM MATCH_ROWS,MATCH_ROW_COUNT
    )
    
    SELECT * FROM PROCESSED_ROWS;

    Hello

    I think you want to put this on a report or something. I have what would be easier to do this logic there. But if you want that this is possible.
    Like this

    with
    temp_aaa as
    (select '111' a_id ,'12345' b_id from dual union all
    select '222'      ,'12345'  from dual union all
    select '333'      ,'12000'  from dual union all
    select '444'      ,'10000'  from dual
    )
    , wanted_rows as
    ( select  '123456' B_ID from dual)
    select
      temp_aaa.A_ID || temp_aaa.B_ID IDS 
    
    from
      temp_aaa
      ,wanted_rows
    where
      temp_aaa.b_id = wanted_rows.b_id
    union all
    select
      'NO ROWS'
    FROM
      DUAL
    WHERE
      (SELECT COUNT(*) FROM TEMP_AAA, wanted_rows WHERE TEMP_AAA.B_ID = wanted_rows.B_ID) = 0
    

    In addition, you mix var and number of always use the same type or convert explicitly (to_number or to_char)

    WITH
    MATCH_ROWS AS
    (
           SELECT A_ID||B_ID IDS FROM TEMP_AAA WHERE      B_ID           =12345
    --                                                    varchar2(10)   number
    ),
    ...
    

    And again in the

                      THEN
                       (SELECT NVL((SELECT IDS FROM TEMP_AAA WHERE B_ID           =12345),'NO ROWS') IDS FROM DUAL)
    --                                                             varchar2(10)   number
    

    Kind regards

    Peter

  • Query to search for users based on the State of the resource

    Hi all

    I'm working on version 9 x IOM. I need to find all the users of a resource that is in "Ready" status in the profile of their resources

    Let say resource Genetiquea is here and for some users of the status of this resource in their resources profile is in "ready". I want to get these users.

    Melyssa, help me with this SQL query.

    Thank you
    Madhu

    Try this query:
    Select usr.usr_login, obj.obj_name, ost.ost_status, usr, obj, obi, Ouedraogo, ost where usr.usr_key = oiu.usr_key and obi.obi_key = oiu.obi_key and obi.obj_key = obj.obj_key and ost.ost_key = oiu.ost_key and obj.obj_name =''

    You can add: and ost.ost_status = to find the status as well.

    Kind regards
    GP

  • Apply the justification for the single line in a paragraph

    Hello

    In InDesign, it is impossible to apply "Justification.FULLY_JUSTIFIED" to the last line of the paragraph only and not for the whole of the paragraph? The last line have SpecialCharacters.COLUMN_BREAK as the last character.

    Thank you.

    vDeepak wrote:

    In InDesign, it is impossible to apply "Justification.FULLY_JUSTIFIED" to the last line of the paragraph only and not for the whole of the paragraph?

    This script will do, with the text cursor inside the paragraph to be staggered.

    par = app.selection[0].paragraphs[0];
    lastLine = par.lines.item(-1);
    while (lastLine.lines.length == 1)
              lastLine.tracking++;
    lastLine.tracking--;
    

    ... The last line have SpecialCharacters.COLUMN_BREAK as the last character.

    The way the paragraph ends is inconsequential for this method. The only thing is, you can't justify the last line if it contains only a single character. Fortunately the script will try to do it but it will never reach its end state; Instead, he will be out to + 10,000 mistake followed since this seems to be a hard-coded limit.

  • Query to search for recursive data

    Hello
    I have a table called orders that has two columns, orderid and originalorderid. the data from this column as below:

    OrderId Active OriginalOrderId
    6 0
    11 6 0
    14-11-1

    I want to write a query such that when I pass the orderid = 14 it returns me OrderID 6 and 11 6 being the first orderid that changed 11 orderid, then 14 orderid.
    How can I write such a request.

    Please notify.

    Thank you
    Reena

    Hello

    @ Centinel: thanks for you Centinel SAMPLES.

    WITH orders AS
        (
                SELECT 6  AS ORDERID, 0  AS ORIGINALORDERID, NULL       AS ACTIVE FROM DUAL UNION ALL
               SELECT 11 AS ORDERID, 6  AS ORIGINALORDERID, 0          AS ACTIVE FROM DUAL UNION ALL
               SELECT 14 AS ORDERID, 11 AS ORIGINALORDERID, 1          AS ACTIVE FROM DUAL
        )           SELECT  max(ltrim(SYS_CONNECT_BY_PATH(ORDERS.ORDERID, ','),','))keep(dense_rank last order by level  )res
               FROM    ORDERS
               START WITH ORDERID != 14
               CONNECT BY ORDERID = PRIOR ORIGINALORDERID
    /
    RES
    --------------------------------------------------------------------------------
    11,6
    
    SQL> 
    
  • How to divide the text block to separate text frames each for a single line.

    I mean the same as a script of the splitstory soon, but I first have to draw all the lines of text in the separate text block.

    How to copy for example consistent with 10 lines of text to separate the 10 images and then divided.

    Dropbox - screen.jpg

    Hello

    Try this,

    var doc = app.activeDocument,
        sel = doc.selection[0],
        _lines = sel.parent.lines,
        txfm = sel.parentTextFrames[0],
        gb = txfm.geometricBounds;
    for(var i =_lines.length-1;i>0;i--)
    {
            var nextframe = txfm.parentPage.textFrames.add({geometricBounds:[_lines[i-1].baseline,gb[1],_lines[i].baseline,gb[3]]});
            nextframe.textFramePreferences.firstBaselineOffset =  FirstBaseline.LEADING_OFFSET;
            txfm.nextTextFrame = nextframe;
        }
    txfm.geometricBounds = [gb[0],gb[1],_lines[0].baseline,gb[3]];
    
    for(var i =sel.parent.textContainers.length-1;i>=0;i--)
    {
            sel.parent.textContainers[i].duplicate();
        }
    for(var i =sel.parent.textContainers.length-1;i>=0;i--)
    {
            sel.parent.textContainers[i].remove();
        }
    

    Kind regards

    Cognet

  • SQL query: only the numbers in the line of the somme - need help

    Pls see data below. I want to display only 8 lines and lines of BRH NCC should be merged and displayed as - BRH 98 2 instead of 2 rows. The rest of the lines must remain as it is. Help, please.


    NCC SERVICES MANUFACTURING
    ASL 138 NA
    BRH 98 NA
    BRH NA 2
    C10000 NA 0
    C40000 NA 0
    DAO NA 10
    E10000 NA 0
    I10000 NA 0
    M10000 NA 0

    Published by: auxilia on November 7th, 2009 06:25
    with t as (
               select 'ASL' ccn,'138' services,'NA' manufacturing from dual union all
               select 'BRH','98','NA' from dual union all
               select 'BRH','NA','2' from dual union all
               select 'C10000','NA','0' from dual union all
               select 'C40000','NA','0' from dual union all
               select 'DAO','NA','10' from dual union all
               select 'E10000','NA','0' from dual union all
               select 'I10000','NA','0' from dual union all
               select 'M10000','NA','0' from dual
              )
    select  ccn,
            nvl(max(case services when 'NA' then null else services end),'NA') services,
            nvl(max(case manufacturing when 'NA' then null else manufacturing end),'NA') manufacturing
      from  t
      group by ccn
    /
    
    CCN    SERVICES             MANUFACTURING
    ------ -------------------- --------------------
    E10000 NA                   0
    C10000 NA                   0
    BRH    98                   2
    M10000 NA                   0
    C40000 NA                   0
    ASL    138                  NA
    I10000 NA                   0
    DAO    NA                   10
    
    8 rows selected.
    
    SQL>   
    

    SY.

    Published by: Solomon Yakobson on November 7th, 2009 06:46

  • arrow keys not working is not for a single line on laptop

    line arrow keys do not work. How can I fix it? arrow down is equal to end of page and arrow up equal top of page. use win 7 computer acer laptop. version of firefox is unknown

    You may have switched to the keyboard navigation.

    You can activate or switch by pressing F7 keyboard navigation (Mac: fn + F7).

    • Tools > Options > advanced > general > accessibility: [] "always use the cursor keys to navigate through the pages."

    Note that this is a function of Firefox Accessibility.

  • Query to search for students by group ID

    Hello

    I have a table that has 2 columns student_id and Course_id.

    Examples of data

    Student_id Course_id
    -------------------------------
    1 > 1
    1 > 2
    1 > 3
    1 > 4
    2 > 1
    2 > 3
    3 > 1
    3 > 2
    3 > 4
    I want to find students who have completed all course 1,3,4.

    Try again with the following query.

    WITH T AS (SELECT 1 stu_id ,     1 stu_curs FROM DUAL
     UNION ALL
    SELECT 1 ,     2 FROM DUAL
     UNION ALL
    SELECT 1 ,     3 FROM DUAL
     UNION ALL
    SELECT 1 ,     4 FROM DUAL
     UNION ALL
    SELECT 2 ,     1 FROM DUAL
     UNION ALL
    SELECT 2 ,     3 FROM DUAL
     UNION ALL
    SELECT 3 ,     1 FROM DUAL
     UNION ALL
    SELECT 3 ,     2 FROM DUAL
     UNION ALL
    SELECT 3 ,     4 FROM DUAL
     )
    select stu_id from t where stu_curs in (1,3,4) group by stu_id having count(0) = 3;
    
  • Problem with SQL query in the view of a line

    Hello

    I have a table TABLEA it has 3 columns:

    Structure of TABLEA

    Code Tax_Code_1 Tax_Code_2

    1A
    1 B


    I want that the output voltage:

    Code Tax_Code_1 Tax_Code_2
    1 A AND B

    Any help will be necessary for me

    Thanks and greetings

    ..

Maybe you are looking for