Please help me write this SQL query...

Hi everyone,

Please help me in this query.
A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and
if they have (M and D) i need to select type M,and if they have only type D i have to select that.
For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag)

Patient table
=============

Patient_id          First_name    last_name

1                   sanjay        kumar
2                   ajay          singh
3                   Mike          John


Adress table
============

address_id       patient_id       adresss       city       type       startdate        enddate      valid_flg

1                   1             6222         dsadsa           P          01/01/2007       01/01/2010
2                   1             63333        dsad             M          01/02/2006       01/01/2007      N
3                   1             64564         fdf              M          01/01/2008       07/01/2009      
4                   1             654757       fsdfsa          D          01/02/2008       09/10/2009  
5                   2             fsdfsd       fsdfsd            M          01/03/2007       09/10/2009   
6                   2             jhkjk        dsad              D          01/01/2007       10/10/2010   
7                   3             asfd         sfds               D          01/02/2008       10/10/2009      


output
=====

1        sanjay       kumar            6222       dsadsa      P          01/01/2007        01/01/2010     
2        ajay         singh            fsdfsd     fsdfsd       M          01/03/2007        09/10/2009 
3        mike         john              asfd       sfds        D          01/02/2008        10/10/2009
Thanks in advance
Phani

Hello, Fabienne,.

This race for you (twisted code of Sarma):

SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
 FROM (
  SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
             ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                      WHEN  'M' THEN 2
                                                                      WHEN  'D' THEN 3
                                                                    END) rn
    FROM  patient p
    JOIN  address a ON (p.patient_id = a.patient_id )
   WHERE NVL(valid_flg, 'X') != 'N'
     AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
     )
WHERE rn = 1; 

Edit, currently in the trial:

With Patient AS (
SELECT 1  Patient_id , 'sanjay' First_name, 'kumar'  last_name FROM DUAL UNION ALL
SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL
SELECT 3, 'Mike', 'John' FROM DUAL),
Address AS (
SELECT 1   address_id, 1  patient_id, '6222'    address, 'dsadsa'   city, 'P'  type, to_date('01/01/2007', 'DD/MM/YYYY')  startdate, to_date('01/01/2010', 'DD/MM/YYYY')  enddate, NULL  valid_flg FROM DUAL UNION ALL
SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'),  ' N'  FROM DUAL UNION ALL
SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL  FROM DUAL UNION ALL
SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'),  NULL  FROM DUAL UNION ALL
SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'),  NULL  FROM DUAL)
-- end test data
 SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate
 FROM (
  SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate,
             ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1
                                                                      WHEN  'M' THEN 2
                                                                      WHEN  'D' THEN 3
                                                                    END) rn
    FROM  patient p
    JOIN  address a ON (p.patient_id = a.patient_id )
   WHERE NVL(valid_flg, 'X') != 'N'
     AND SYSDATE BETWEEN startdate AND  NVL(enddate, SYSDATE)
     )
WHERE rn = 1; 

PATIENT_ID FIRST_ LAST_ ADDRESS CITY   TY STARTDATE ENDDATE
---------- ------ ----- ------- ------ -- --------- ---------
         1 sanjay kumar 6222    dsadsa P  01-JAN-07 01-JAN-10
         2 ajay   singh fsdfsd  fsdfsd M  01-MAR-07 09-OCT-09
         3 Mike   John  asfd     sfds  D 01-FEB-08 10-OCT-09

Tags: Database

Similar Questions

  • Please help me with this SQL query

    I'm practicing of SQL queries and met one involving the extraction of data from 3 different tables.

    The three paintings are as below

    < pre >
    Country
    Location_id country
    LOC1 Spain
    loc2 England
    LOC3 Spain
    loc4 USA
    loc5 Italy
    loc6 USA
    loc7 USA
    < / pre >
    < pre >


    User
    user_id location_id
    loc1 U1
    loc1 U2
    loc2 U3
    loc2 U4
    loc1 U5
    U6 loc3
    < / pre >
    < pre >


    Publish
    user_id post_id
    P1 u1
    P2 u1
    U2 P3
    P4 u3
    P5 u1
    P6 u2
    < / pre >

    I am trying to write a SQL query - for each country of the users, showing the average number of positions

    I understand the logic behind all this that we must first consolidate all locations, and then the users in one country and then find the way to their positions.
    But, I'm having a difficulty to this format SQL. Could someone help me please with this request.

    Thank you.

    Select
    Country.Country,
    Count (*) Totalpostspercountry,
    Count (distinct post.user_id) Totaldistincuserspercountry,
    count (*) / count (distinct post.user_id) Avgpostsperuserbycountry
    Of
    countries, have, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    Country.country group

    The output is like this for your sample data - hope that's what you're looking for :)

    COUNTRY, TOTALPOSTSPERCOUNTRY, TOTALDISTINCUSERSPERCOUNTRY, AVGPOSTSPERUSERBYCOUNTRY
    In England, 1, 1, 1.
    Spain, 5, 2, 2.5.

  • Please help me fix this SQL query...

    Hi, please consider following:
    create table test (col varchar2 (255))
    insert into test values ("TERM").
    Insert test values ("VOLUME");

    Select the test pass where pass in ('TIME', 'VOLUME');
    This property returns the rows.

    but my input string is a comma-separated list:
    DURATION, VOLUME

    so I try
    Select the test pass where col to (replace (' DURATION, VOLUME, ',' "'," '));
    but no result. Or:
    Select the test pass where col in ("' | replace (' DURATION, VOLUME, ','" ', "') |") ') ;

    However
    Select "' | Replace (' DURATION, VOLUME, ',' "'," ') | " ' the double
    gives "DURATION", "VOLUME".

    then why does it work?

    hope you can help. Thank you

    convert stringlist in lines and then use in the clause...

    SELECT col
       FROM test
      WHERE col IN
      (SELECT    *
         FROM
        (SELECT TRIM( SUBSTR ( txt , INSTR (txt, ',', 1, level ) + 1 , INSTR (txt, ',', 1, level+1 ) - INSTR (txt, ',', 1, level) -1 ) ) AS token
           FROM
          ( SELECT ','||'DURATION,VOLUME'||',' AS txt FROM dual
          )
          CONNECT BY level <= LENGTH(txt)-LENGTH(REPLACE(txt,',',''))-1
        )
      )
    

    Ravi Kumar

  • Need help to write a SQL query complex

    I have the source tabe as below

    -> SOURCE_TABLE
    NAME     CUST_ID     SVC_ST_DT     SVC_END_DT 
    TOM        1               31/08/2009      23/03/2011 
    DOCK       2               01/01/2004      31/05/2010 
    HARRY      3               28/02/2007      31/12/2009 
    I want to load as target table below
    -> TARGET_TABLE
    NAME     CUST_ID                     SVC_ST_DT      SVC_END_DT 
    TOM      1           31/08/2009      31/12/2009 
    TOM      1           01/01/2010      31/12/2010 
    TOM      1           01/01/2011      23/03/2011 
    DOCK      2           01/01/2004      31/12/2004 
    DOCK      2           01/01/2005      31/12/2005 
    DOCK      2           01/01/2006      31/12/2006 
    DOCK      2           01/01/2007      31/12/2007 
    DOCK      2           01/01/2008      31/12/2008 
    DOCK      2           01/01/2009      31/12/2009 
    DOCK      2           01/01/2010      31/05/2010 
    HARRY      3           28/02/2007      31/12/2007 
    HARRY      3           01/01/2008      31/12/2008 
    HARRY      3           01/01/2009      31/12/2009 
    Is it possible to write a SQL query that returns the data in the same way above the target table.

    Published by: AChatterjee on April 30, 2012 07:14

    Published by: AChatterjee on April 30, 2012 07:14

    Or like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'TOM' as NAME, 1 as CUST_ID, date '2009-08-31' as SVC_ST_DT, date '2011-03-23' as SVC_END_DT from dual union all
      2             select 'DOCK', 2, date '2004-01-01', date '2010-05-31' from dual union all
      3             select 'HARRY', 3, date '2007-02-28', date '2009-12-31' from dual)
      4  --
      5  -- end of test data
      6  --
      7  select name, cust_id, svc_st_dt, svc_end_dt
      8  from (
      9        select name
     10              ,cust_id
     11              ,greatest(svc_st_dt, add_months(trunc(svc_st_dt,'YYYY'),yr*12)) as svc_st_dt
     12              ,least(svc_end_dt, add_months(trunc(svc_st_dt,'YYYY'),(yr+1)*12)-1) as svc_end_dt
     13        from t
     14             cross join (select rownum-1 as yr
     15                         from   dual
     16                         connect by rownum <= (select extract(year from max(svc_end_dt)) - extract(year from min(svc_st_dt)) + 1 from t)
     17                        )
     18       )
     19  where svc_st_dt <= svc_end_dt
     20* order by 2, 3
    SQL> /
    
    NAME     CUST_ID SVC_ST_DT            SVC_END_DT
    ----- ---------- -------------------- --------------------
    TOM            1 31-AUG-2009 00:00:00 31-DEC-2009 00:00:00
    TOM            1 01-JAN-2010 00:00:00 31-DEC-2010 00:00:00
    TOM            1 01-JAN-2011 00:00:00 23-MAR-2011 00:00:00
    DOCK           2 01-JAN-2004 00:00:00 31-DEC-2004 00:00:00
    DOCK           2 01-JAN-2005 00:00:00 31-DEC-2005 00:00:00
    DOCK           2 01-JAN-2006 00:00:00 31-DEC-2006 00:00:00
    DOCK           2 01-JAN-2007 00:00:00 31-DEC-2007 00:00:00
    DOCK           2 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    DOCK           2 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    DOCK           2 01-JAN-2010 00:00:00 31-MAY-2010 00:00:00
    HARRY          3 28-FEB-2007 00:00:00 31-DEC-2007 00:00:00
    HARRY          3 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    HARRY          3 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    
    13 rows selected.
    
  • Need help to write the SQL query

    Hello
    Please help me to write a query. My requirement is as below.

    Hello
    I have a table say XYZ in the following format.

    product_id local min_order_quntity
    ========================================
    1 en 10
    1 ch 10
    2 en 20
    2 ch 20
    3 en 30
    3 ch 30
    4 en 40
    4 NC 10

    Now I want to find the product_id where min_order_quantity is different for cn and locale

    now I want the result of the following

    product_id local min_order_quantity
    =============================================
    4          en          40
    4 ch 10

    This is different for local in and cn for product_id 4 min_order_quantity

    min_order_quantity should be the same for both the locale(en,ch) for any product_id.

    I want to find the product_id where min_order_quantity is different for ch and fr local

    Thank you..

    Hello

    This query should do the job

    select * from xyz t1
    where exists ( select 1 from xyz t2 where t2.product_id = t1.product_id and
                   t2.locale != t1.locale and t2.min_order_quantity != t1.min_order_quantity );
    

    See you soon

  • Please help to write a complex query "select".

    Hello

    I am trying to write a query that retrieves information about attachments in HP ALM by referring to TestInstances, TestRun and TestSteps tables. For those who do not know HP ALM...

    I'm describing the structure of data in these tables (the names of tables and fields are changed for easy understanding).

    > > 1. In the "TestInstances" table key fields are I_InstanceID, I_HasAttachments and I_TestSetID

    1.1 I_InstanceID is the primary key for this table

    > > 2. Key in the table "TestRuns" fields are R_RunID, R_InstanceID, R_RunTime and R_HasAttachments

    2.1 R_RunID is the primary key for this table

    2.2 R_InstanceID is a foreign key to I_InstanceID in the TestInstances table

    2.3 all I_InstanceID in the TestInstances table may not have an entry in the table TestRuns

    2.4 an I_InstanceID in TestInstances can have multiple entries in the table TestRuns with different R_RunID

    > > 3. In the "TestSteps" table key fields are S_StepID, S_RunID and S_HasAttachments

    3.1 S_StepID is the primary key for this table

    3.2 S_RunID is a foreign key to R_RunID in the TestRuns table

    3.3 all R_RunID in the TestRuns table may not have an entry in the TestSteps table

    3.4 a R_RunID in TestRuns can have multiple entries in the table TestSteps with different S_StepID

    Entry to the query I want to write is a set of I_TestSetID in the TestInstances table (which I already have)

    The desired query output is -.

    1. all I_InstanceID have the values as shown in the entry I_TestSetID

    2 I_HasAttachments corresponding to I_InstanceID

    3. Earl of R_RunID against each I_InstanceID (may be 0 or a positive integer)

    4. only the last R_RunID corresponding to each I_InstanceID (later are using MAX (R_RunID) GROUP BY I_InstanceID)

    5 R_HasAttachment value of last R_RunID

    6 R_RunTime last R_RunID value

    7. County of S_StepID against each R_RunID (may be 0 or a positive integer)

    8. County of S_HasAttachment against each R_RunID (may be 0 or a positive integer and may differ from the County of S_StepID)

    Friends, could one of you give it a try and help out me?

    Thanks in advance!

    PS: This had been driving me crazy for 3 days. I'm not able to get unique entries and entries for which references to the TestRun and TestStep tables are empty.

    Try the bottom of correlated subquery

    SELECT i_instanceid,

    i_hasattachments,

    (SELECT COUNT (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid) cnt_runid;

    (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid) cnt_latestrunid;

    (SELECT I_HasAttachments

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid

    AND tr.r_runid = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)) R_HasAttachments;

    (SELECT R_RunTime

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid

    AND tr.r_runid = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)) R_RunTime;

    (SELECT COUNT (S_StepID)

    OF TestSteps ts

    WHERE the ts. S_RunID = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)) cnt_stepid;

    (SELECT COUNT (S_HasAttachments)

    OF TestSteps ts

    WHERE the ts. S_RunID = (SELECT MAX (R_RunID)

    OF TestRuns tr

    WHERE tr.r_instanceid = ti.i_instanceid)

    AND S_HasAttachments = 'Y') cnt_SHasAttachment

    OF ti TestInstances

    WHERE I_TestSetID IN (1190,1191,1192,1194,1195);

  • Please explain to me this sql query

    Select * from emp e
    where 2 > (select count (sal) from emp where the e.sal < sal)

    It gives higher and the second highest salary, but how it works I HAV eno no idea please let me know briefly.

    Hello
    is
    Welcome to the forum!

    Thus, you have a query like

    SELECT  *
    FROM    emp     e
    WHERE   2 > x;
    

    and you want to understand how it works. I guess the part that you don't understand is so x, x display.

    SELECT  e.*
    ,       x
    FROM    emp     e
    WHERE   2 > x;
    

    Since the clause WHERE eliminates most of the lines, we will not use a WHERE clause for now. Also, we will simply display a couple of columns, just so that we can concentrate on the important parts better. We will only display the sal (because the query has something to do with the highest sal) and something unique on each line, like ename. Is, try to run something like this:

    SELECT       ename, sal
    ,       (
             SELECT  COUNT (sal)
             FROM    emp
             WHERE   e.sal     < sal
           )     AS x
    FROM       emp     e
    ORDER BY  sal
    ;
    

    Output:

    ENAME             SAL          X
    ---------- ---------- ----------
    SMITH             800         13
    JAMES             950         12
    ADAMS            1100         11
    WARD             1250          9
    MARTIN           1250          9
    MILLER           1300          8
    TURNER           1500          7
    ALLEN            1600          6
    CLARK            2450          5
    BLAKE            2850          4
    JONES            2975          3
    SCOTT            3000          1
    FORD             3000          1
    KING             5000          0
    

    You see what x is now? This is the number of lines where sal is higher than sal on the current line.
    Nobody has one of its KING sal, so x = 0 to the rank of KING.
    Only 1 person (that is, the KING) has a higher sal of SCOTT, so x = 1 on the line for SCOTT.
    13 persons (that is, everyone except SMITH) has a greater sal then SMITH, so x = 13 on the BOF SMITH line.

  • Better way to write this sql?

    Hi guru, I was able to get what I want, but I find there must be a better way/more efficient way to write this sql?

    Database: Oracle 11g

    This is the create for the test database statement:

    create table sample_test (prog_id number (9) DEFAULT 0 NOT NULL, chan_rights CHAR (2) DEFAULT ' ' NOT NULL)

    This is the insert statement:

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (555633, 'A1')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (555633, 'A2')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (555633, 'A3')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (555633, 'A4')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (555633, 'A5')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (555633, 'A6')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (555633, 'A7')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (495641, 'A1')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (495641, 'A2')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (495641, 'A3')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (495641, 'B1')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (495641, 'B2')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (495641, 'B3')

    INSERT INTO sample_test (prog_id, chan_rights) VALUES (495641, 'B4')

    Here's what I did to get the data:

    Select distinct a.prog_id, rt_cnt, CASE

    WHEN a.rt_cnt = 7

    and there are (select 'Y' b sample_test where a.prog_id = b.prog_id and b.chan_rights = 'A1')

    and there are (select 'Y' b sample_test where a.prog_id = b.prog_id and b.chan_rights = "A2")

    and there are (select 'Y' b sample_test where a.prog_id = b.prog_id and b.chan_rights = "A3")

    and there are (select 'Y' b sample_test where a.prog_id = b.prog_id and b.chan_rights = 'A4')

    and there are (select 'Y' b sample_test where a.prog_id = b.prog_id and b.chan_rights = 'A5')

    and there are (select 'Y' b sample_test where a.prog_id = b.prog_id and b.chan_rights = 'A6')

    and there are (select 'Y' b sample_test where a.prog_id = b.prog_id and b.chan_rights = 'A7')

    THEN "A_ONLY".

    else 'SINGLE '.

    end CHAN_GROUP

    from (select prog_id, count (chan_rights) rt_cnt

    of sample_test

    Prog_id group) a, b sample_test

    where a.prog_id = b.prog_id

    That appears as follows:

    PROG_ID RT_CNT CHAN_GROUP
    4956417UNIQUE
    5556337A_ONLY

    As seen:

    1 / I count how many rights is available, and in this case, each program gets a "7"

    Set 2 / from these data, for each programme, I try to make sure it belongs to the company chan_rights right, for example, "A_ONLY". Therefore, as shown, Prog_ID 495641 does not contain "A_ONLY" channels listed in the case statement and there is unique. "A_ONLY" should only contain A1 to A7 inclusive and nothing else.

    Can I create a function that returns the value "Chan_Group", but is there a better way to rewrite the statement 'BOX' like a LOOP or something? I have millions of records to go through and someone told me that using "is" slows down the database so just thought that I could ask ahead...

    Please indicate if there is a better and more efficient method to get what I need?

    Thank you

    John

    I would do something like

    select prog_id,
          rt_cnt,
          (case when rt_cnt = 7 and num_a = 7
                then 'A_ONLY'
                else 'UNIQUE'
            end) chan_group
      from (select prog_id,
                  count(chan_rights) rt_cnt,
                  sum( case when chan_rights in ('A1','A2','A3','A4','A5','A6','A7')
                            then 1
                            else 0
                        end ) num_a
              from sample_test
            group by prog_id)
    

    View of inline, I count the number of values chan_rights, as well as the number that are in your list of A1 - A7.  In the outer query, I implement the logic that checks that the two charges are 7.

    Here is an example of sqlfiddle this http://www.sqlfiddle.com/#! 4/95438/2

    Justin

  • How to prevent a user not to access a table of perticular? This user has select any table privilege. Please help me solve this problem.

    Hello

    How to prevent a user not to access a table special (xxx)?

    This user has SELECT a TABLE ALL privilege. I need to restrict to only not for access xxx to the table, but this table is not existed in its own schema.

    But there is access able as select * from schema.table;

    How can I revoke this privilege.

    Please help me solve this problem.

    Thank you

    Lacombe

    1623609 wrote:

    How can I select privilege on specific tables at the same time?

    I want to create a new user and grants the right to select for tables, except a table (xxxx).

    It will be possible without the keystone of the database?

    One way, in several sql

    coil doit.sql

    Select ' grant select on ' | owner: '. ' || table_name |' to someuser. »

    from dba_tables

    where

    spool off

    Then sanity check "doit.sql" and execute it.

  • Write a SQL query with lines in columns

    All the

    I need help in writing a SQL query with lines in columns, let give u an example...

    drop table activity;

    CREATE TABLE 'ACTIVITY '.

    (

    "PROJECT_WID" NUMBER (22.0) NOT NULL,

    VARCHAR2 (150 CHAR) "PROJECT_NO."

    VARCHAR2 (800 CHAR) 'NAME '.

    );

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');

    Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');

    drop table lonet;

    CREATE TABLE 'LONET.

    (

    VARCHAR2 (150 CHAR) "NAME."

    NUMBER OF THE "ROOT."

    VARCHAR2 (150 CHAR) "ENTRYVALUE".

    );

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");

    INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");

    commit;

    Link: activity.project_wid = lonet.root

    look like output

    Project_wid Project_no NAME GAC NAM BAG RAC
    16836911000712-121LDELMELCELKE
    16849941000812-122MTEnullnullMAC
    16862961000912-123nullnullCAQQAQ
    2225222904012-124nullnullnullnull

    two problems, in that I am running

    1. I dono how simply we can convert rows to columns

    2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value

    3. There are undesirables who should be ignored

    Once again my thought process is that we join the activity and 4 alias table lonet.

    ask for your help in this

    Thank you

    Hello

    This is called pivoting.

    Here's a way to do it:

    WITH relevant_data AS

    (

    SELECT a.project_wid, a.project_no, b.SID

    , l.name AS lonet_name, l.entryvalue

    Activity one

    LEFT OUTER JOIN lonet l.root = a.project_wid l

    )

    SELECT *.

    OF relevant_data

    PIVOT (MAX (entryvalue)

    FOR lonet_name IN ("GAC" IN the gac

    "NAM" AS nam

    'BAG' IN the bag

    "RAC" AS cars

    )

    )

    ORDER BY project_wid

    ;

    Output:

    PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME

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

    1683691 12 - 10007 121 LDE LME LCE LKE

    1684994 MAC MTE 10008 12-122

    1686296 12 - 10009 123 QAC QAQ

    2225222 9040 12 - 124

    To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • Please let me know how I can add a new column with a constraint not null, table already has data, without falling off the table... Please help me on this issue...

    Hello

    I have an emp_job_det with a, b, c columns table. Note that this TABLE ALREADY has DATA OF THESE COLUMNS

    IAM now add a new column "D" with forced not null

    Fistly I alter the table by adding the single column "D", if I do, the entire column would be created with alll of nulls for the column DEFAULT D

    ALTER table emp_job_det Add number D; -do note not null CONSTRAINT is not added

    Second... If I try to add the constraint not null, get an eoor as already conatained null values...

    (GOLD)

    In other words, if I put the query

    ALTER table emp_job_det Add number D NOT NULL; -THROWS ERROR AS TABLE ALREADY CONTAINS DATA

    So my question is how how can I add a new column with a constraint not null, table already has the data, without falling off the table

    Please help me on this issue...

    Add the column without constraint, then fill the column. Once all the rows in the table are given in the new column, and then add the constraint not null.

  • After updating my iPhone 6 (9.3.4) the WiFi signal becomes very low! I did everything, but the problem does not stop! I don't a not update my other devices &amp; their very good WiFi signals. Please help me solve this terrible problem...

    After updating my iPhone 6 (9.3.4) the WiFi signal becomes very low! I did everything, but the problem does not stop! I don't a not update my other devices & their very good WiFi signals. Please help me solve this terrible problem...

    Here's a tip for the user on the problems of Wi - Fi. Suggest from the top and bottom. Maybe one of them will help you.

    (1) restart you device.

    (2) resetting the network settings: settings > general > reset > reset network settings. Join the network again.

    (3) reboot router/Modem: unplug power for 2 minutes and reconnect. Update the Firmware on the router (support Web site of the manufacturer for a new FW check). Also try different bands (2.4 GHz and 5 GHz) and different bandwidths (recommended for 2.4 to 20 MHz bandwidth). Channels 1, 6 or 11 are recommended for 2.4 band.

    (4) change of Google DNS: settings > Wi - Fi > click the network, delete all the numbers under DNS and enter 8.8.8.8 or otherwise 8.8.4.4

    (5) disable the prioritization of device on the router if this feature is available. Also turn off all apps to VPN and retest the Wi - Fi.

    (6) determine if other wireless network devices work well (other iOS devices, Mac, PC).

    (7) try the device on another network, i.e., neighbors, the public coffee house, etc.

    (8) backup and restore the device using iTunes. Try to restore as New first and test it. If ok try to restore the backup (the backup may be corrupted).

    https://support.Apple.com/en-us/HT201252

    (9) go to the Apple store for the evaluation of the material. The Wi - Fi chip or the antenna could be faulty.

    Council: https://discussions.apple.com/docs/DOC-9892

  • The address bar where I can type in the Web addresses does not appear on my Mozilla, please help me with this... How to activate it?

    The address bar where I can type in the Web addresses does not appear on my Mozilla, please help me with this... How to activate it?

    Hi kdwis,

    Going to try view > toolbars and activation of the Bar of Navigation and in the bookmarks toolbar.

    Hope this helps!

  • I can't shoot at a site in the usual browser... in navigation private. I can pull up in other browsers and could pull up 2 weeks ago... now I can't. Please help me solve this problem?

    Question
    I can't shoot at a site in the usual browser... in navigation private. I can pull up in other browsers and could pull up 2 weeks ago... now I can't. Please help me solve this problem? Also, I can' signed in 'members only' in private browsing mode.

    Clear the cache and cookies from sites that cause problems.

    "Clear the Cache":

    • Tools > Options > advanced > network > storage (Cache) offline: 'clear now '.

    'Delete Cookies' sites causing problems:

    • Tools > Options > privacy > Cookies: "show the Cookies".
  • I bought the iphone 6 s more time face in Saudi Arabia. I need to check if the original phone to apple or duplicated. So please help me find this problem.

    I bought the iphone 6 s more time face in Saudi Arabia. I need to check if the original phone to apple or duplicate. So please help me find this problem.

    Hey there, I guess your question is "how to determine if my iphone is true or false. If Yes, then if you go here https://selfsolve.apple.com/agreementWarrantyDynamic.do just enter your serial number and code and if his 'real', then it will show you the model of the Iphone and guaranteed dates. If this isn't the case, then you know the rest. If this is not the case then try to download apps from the app store and run or can it connect to itunes. Tell me what best worked: D - Jon

Maybe you are looking for

  • Keypad lock

    Upgrade to iOS 10 freezes my keyboard on iphone6. Close the application and reopen for a few keystrokes more if it. Sometimes the whole phone freezes. Tried to reset the keyboard without result. Updated latest patch hoping that it would work, but no.

  • HP Omen: update the BIOS

    HP support assistant shows that there is the following update: HP notebook System BIOS updateNumber SoftPaq SP74378version F.34Ap1 tried to download and install without success should I worry? Thank you

  • Small problems.

    Hello!I am an old user of Skype, its updated version a few weeks (using right now at 6.22), but... This day "ruin" a bit due to the in the form of shortcuts (* bold * and _italique_). I wanted to leave the Skype as it was before without these shortcu

  • Satellite A200-13O - USB port does not work

    Can you help me? I have a new Satellite A200-13O, USB does not work.

  • When prompted to enter my password for internet banking, page does not load and then link is broken and connection is lost.

    When I try to connect to the page it requires me to enter a password before entering the Web site. When the Web site attempts to load, the connection is lost and I need to enter again with the password again. I called the hotline of the Web site and