How to display rows of data in different columns?

I'm new to SQL and currently, that's what I try to do:

Display multiple lines of data in different columns in the same row

I have a table like this:

CREATE TABLE TRIPLEG)

T # NUMBER (10) NOT NULL,

STEP # NUMBER (2) NOT NULL,

DEPARTURE VARCHAR (30) NOT NULL,

VARCHAR (30) DESTINATION NOT NULL,.

CONSTRAINT TRIPLEG_PKEY PRIMARY KEY (T #, LEG #).

TRIPLEG_UNIQUE UNIQUE CONSTRAINT (T #, DEPARTURE, DESTINATION).

CONSTRAINT TRIPLEG_FKEY1 FOREIGN KEY (T #) REFERENCES TRIP(T#));

INSERT INTO TRIPLEG VALUES (1, 1, 'Sydney', 'Melbourne');

INSERT INTO TRIPLEG VALUES (1, 2, 'Melbourne', 'Adélaïde');

The result should be something like this:

> T # | ORIGIN | DESTINATION1 |  DESTINATION2

> 1 | SYDNEY | MELBORUNE | ADELAIDE

The request must include the ' COUNT(T#) < 3' since I only need to display the records of less than 3. How can I get the results I want to use relational views?

Thank you!!!

I replaced the syntax "where" with the syntax 'account '. The reason why I do this is because I want to only display records with a number of travel of less than 3. By defining where the legs #.<=3, the="" result="" will="" be="" all="" the="" records="" of="" the="" tripleg="" table="" since="" each="" record="" could="" also="" have="" leg#="" is="">

The answer is:

with t as (SELECT t #,)

REGEXP_REPLACE)

LISTAGG (start |) '->' || destination, ' ')

THE Group (ORDER BY t #, leg #).

'([^ ]+) \1+',

"\1") str

OF tripleg

HAVING COUNT (T #)<>

GROUP BY t #)

Select T #, regexp_substr (str, ' [^->] +', 1, 1) departure

, regexp_substr (str, ' [^->] +', 1, 2) destination_1

, regexp_substr (str, ' [^->] +' 1, 3) destination_2

, regexp_substr (str, ' [^->] +' 1, 4) destination_3

Thanks to Marty and knani!

Tags: Database

Similar Questions

  • How to display on my screen 2 different applications at the same time?

    How to display on my screen 2 different applications at the same time?

    Hello

    The best place to ask would be the forums for answers corresponding to your version of Windows.

    Answers - Windows Forums
    http://answers.Microsoft.com/en-us/Windows

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

    If you have Windows 7 with Aero - click with the right button on the taskbar at the bottom of the screen and click on 'show windows '.
    Side by Side.

    For all versions of Windows:

    You could also reduce less than full screen using the small box to the left of the red X at the top right
    and then resizing windows as you want.

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle=""><- mark="" twain="" said="" it="">

  • BI Layout Editor - how to display the current date?

    Hello

    Recently used BI Layout Editor (previously using MS Word to create the presentation of the State).

    He seems really nice and easy to use.

    However quick Q - How to display the current date in the layout editor (to show the report run date).

    Any quick suggestions is appreciated.

    Thank you

    Vivek

    Tab displays your selection available.

    It's like how when you insert the table in the Word document and when you select the table, you would see 2 additional tabs such as the design and the tool.

    Can you please insert "Text Element" and select the text element and see if you go to the tab 'text '?

  • How to display a given date in a DateField?

    Hi Experts,

    I'm developing an app for BlackBerry in Java. I want to display a date I will give statically for example "October 4, 2008. I did, but while reading, it is displayed in January 1, 1970. How can I display a static date in a DateField?

    Thank you and best regards,

    Nithya

    Simple use.

    import java.util.Date;

    Net.rim.device.api.i18n import. *;

    String date = new SimpleDateFormat("dd/MM/yyyy_hh:mm").format (new Date (System.currentTimeMillis ()));
    Add (new RichTextField (date));

  • How to display the current date in a textfield?

    Hi all

    I have a textfield, and it is a part of the P18_DOJ page. By defalut that I want to display today's date to the textfield and it is should be readonly. How do I do that?

    Put "Select sysdate from dual;" as the source SQL Query type and "readonly" in the field of the HTML Form element attributes.

  • How to display the current date in a project CP5?

    What is the best way to display the current date in captivate?

    Hello

    Use a text caption in which you insert the system variable cpInfoCurrentDate.

    Insert a variable is possible with the X in the Format of the text caption properties panel accordion:

  • How to display the current date in a Flex application

    I need to display the current date in my Flex application.  Is there a simple way to do this and post it as a text field or label?  In addition, it can be formatted to display the date as "day of the week, month, day, year"?

    Thank you!

    You can use this page and copy the following code to change the formatString property.

    http://livedocs.Adobe.com/Flex/3/langref/MX/formatters/DateFormatter.html#FormatString

    If this post answers your question or assistance, please mark it as such.

    
    http://www.adobe.com/2006/mxml"
      creationComplete="init();">
      
        
      
      
      
    
    
  • How to display all the data to a database with the same name?

    I am familiar with the creation of basic website, but I want to learn how to create more dynamic Web sites.

    I create a Web site where a user can register on the site and counts there. Once into account here, there will be different options they can do.

    The new application form is in the section account it is configured for a user to submit a multiple application and save it in the database, that works, but the problem I have is during the examination of the application, it does show that one of them, not all.

    How can view the request of a user, sign in?datab.PNG

    revreq.PNG

    I can get to the screen, but not all.

    Is it possible to do this or any suggestions on how to do?

    Here's the code for the ReviewRequest:

    <? PHP require Connections/Connections.php"?" >

    <? PHP

    session_start();

    {if (isset($_SESSION["fname"]))}

    }

    else {}

    Header('Location:NewRequest.php');

    }

    ? >

    <? PHP

    $User = $_SESSION ['Pnom"];

    $result = $con-> query ("SELECT ALL * from newrequest where Fname ="$User"" ");

    $row = $result-> fetch_array (MYSQLI_BOTH);

    $_SESSION ["FirstName"] = $row ["Fname"];

    $_SESSION ['location'] = $row ["Location"];

    $_SESSION ['description'] = $row ['Description'];

    ? >

    <! doctype html >

    < html >

    < head >

    < link href = "CSS/Master.css" rel = "stylesheet" type = "text/css" / > "

    < link href = "CSS/Menu.css" rel = "stylesheet" type = "text/css" / > "

    < meta charset = 'utf-8 '.

    ReviewRequest < title > < / title >

    < / head >

    < body >

    < div class = "Container" >

    < div class = "Header" > < / div >

    < div class = "Menu" >

    < div id = 'Menu' >

    < nav >

    < ul class = "cssmenu" >

    < li > < a href = "Account.php" > account < /a > < /li > ""

    < li > < a href = "UpdateAccount.php" > update account < /a > < /li > ""

    < li > < a href = "NewRequest.php" > new request < /a > < /li > ""

    < li > < a href = "ReviewRequest.php" > Review Request < /a > < /li > ""

    < li > < a href = "LogOut.php" > sign out < /a > < /li > ""

    < /ul >

    < / nav >

    < / div >

    < / div >

    < div class = "LeftBody" > < / div >

    < div class = "RightBody" >

    < name of the form = "form1" method = "post" action = "" >

    < div class = "FormElement" >

    < label for = "FirstName" > < / label >

    < input name = "FirstName" type = 'text' required class = "TField" id = "First name" value = "<?" PHP echo $_SESSION ['FirstName'];? ' > ' >

    < / div >

    < div class = "FormElement" >

    < label for = 'Place' > < / label >

    < input name = "Location" type = 'text' required class = "TField" id = 'Location' value = "<?" PHP echo $_SESSION ['Location'];? ' > ' >

    < / div >

    < div class = "FormElement" >

    < label for = "Description" > < / label >

    < input name = "Description" required class = "TField" id = "Description" value = "<?" PHP echo $_SESSION ['Description'];? ' > ' >

    < / div >

    < / make >

    < / div >

    < div class = "Footer" > < / div >

    < / div >

    < / body >

    < / html >

    You would browse the information stored in the $result variable.

    $result = $con-> query ("SELECT ALL * from newrequest where Fname ="$User"" ");

    As below:

    fetch_assoc()) {? >}

    (I don't see a reason to assign data to a variable of $_SESSION?)

    You also probably would be well advised to select information based on a uniquie rather than a name id - if two people have the same name youre UNLESS you want to make sure that two identical Fname can be stored in your tabe stuffed.

    $result = $con-> query ("SELECT ALL * from newrequest where userID = '$userID'");

    userID |     Fname |     Location |                      Description

    8 the end of the road muddy and foggy

    11 this something, no idea

    8               the              rstreet                           rah

    8 is not a clue

    14 Hello Goodbye

  • How to create views of data from different databases tables in2

    Using Oracle 10.2 g

    I have 2 databases Gus and the haggis on schema Comqdhb.

    Glink indicates a link of database between Haggis and Gus

    In Gus, there is school that contains columns with same name upn, grade, subject, student of tables...

    STUDENT
    UPN
    academicYear

    Object

    Object

    GRADE
    examlevel
    grade

    SCHOOL
    SN

    In HAGGIS raising tables, grade, teacher containing columns upn... desc below.

    STUDENT
    UPN

    GRADE
    grade
    UPN
    academicyear
    level



    Create views in your database HAGGIS who join their all the qualities of the review. You should have a point of view that will produce the following relationship:
    examGrade (upn, subject, examlevel, sn, rank, academicYear)

    So I need to create a view that gets the data from the tables in the databases.

    create view as examGrade (upn, subject, examlevel, sn, rank, academicYear) like some s.upn


    But I don't get the selection of a column of 2 tables in different databases

    I mean if I said

    Select the UPN in comqdhb.student@glink,comqdhb.student;
    Select the upn name in comqdhb.student@glink,comqdhb.student
    *
    ERROR on line 1:
    ORA-00918: column ambiguously defined

    Help me, thank you.

    Hello

    Rider wrote:
    The issue is that I can't understand that I should create the view by the union of the haggis and the two gus data or only haggis.
    the reason I believe I need to combine the two is mentioned * "" create views in your database schema HAGGIS who join their all the qualities of the review. ". *
    By the mention of creating views and who join their all the qualities of the review, it probably means to obtain the data of the GUS and HAGGIS.

    This is my interpretation of the assignment, too.
    If you ask just the tables on Gus, you will get the ranks of three of the four schools: it's not all examination classes.
    If you ask just the tables on Haggis, you will get the ranks of any of the four schools: it's not all examination classes.

    2nd prob is that if have decided to create a view that gets the data from these two gus and therer haggis would be a lot of duplication involved due to the cross product

    Why would there be "repetition involved due to the cross-product"?
    If the quuery of Gus produces 100 lines, the request of product Haggis 30 rows, then the UNION of the two will have 100 + 30 = 130 lines (assuming, as you say, each student is at school only one).

    the query I wrote is

    Create view examGrade (upn, subject, examlevel, sn, rank, academicYear)
    as
    Select distinct s.upn as upn, g.subject as topic,
    g."LEVEL" as examlevel, g.grade as rank, to_number (g.academicyear) as academicyear
    of s comqdhb.student, comqdhb.grade g
    s.UPN, sb.subject, g.elevel, g.grade, s.acyr select Union
    of comqdhb.subject@glink sb,comqdhb.student@glink s,comqdhb.gradevalues@glink g;

    You should not write, not to mention not formatted zip code. I have a little time I can devote to answering questions in the forum. Do you want me
    b spend this time formatting your code, so I can understand the question, and no time to answer, or
    b spend only a little time reading understanding your code and spend most of my time to help you?
    I would prefer (b), but the choice is yours.
    See the statement that I posted in my last post for an example of the formatted code. You see how it appears in a box with a police fixed-width, and multiple spaces are printed? This is because I typed {code} (all small letters), before and after the section I wanted formatted.

    At least put each table in the FROM clause on a separate line, so it is easy to know if you have enough join conditions.
    If you have N tables in the FROM clause, you almost always have at least N-1 join conditions that specify how the tables are linked together. For example, if talk you about two tables, quality and student, you expect to see a join condition that tells you when you have data in a table, how to find related data in the other table, such as

    g_gus.upn = s_gus.upn
    

    No no no join conditions will cause "repetition involved due to the cross product.

    I downloaded my info here
    http://www.upload4free.com/download.php?file=44201983-School_ExamGrades.PDF


    http://www.upload4free.com/download.php?file=184648736-ExamGrades_Case_Study_2008FINAL.PDF

    Sorry, if there is data as long as you can't post here, there is much too much for me to read.
    Make a sample set, containing a few (maybe five) students and a few shades of each student. It is fine to copy a few lines of your actual data.

    That's all the time I have for today. I can't wait to get the data and formatted requests.

  • How to display the exact DATE of my first access to a Web site?

    I need to see when I first consulted several Internet sites. History does not show it, but maybe I'm missing something.
    I appreciate all help.

    ~ airix

    In history, Firefox only displays the most recent visit to a given URL. To find previous visits, you need a tool that allows you to view old data in the database places.sqlite. These discussions have discussion of a few options:

  • XMLP: How to display row XML field in the same column

    Hello

    I show a particulare column in my group of LINE in a single cell of table RTF?

    Example of XML data:

    < L_LINE_GROUP >

    < G_LINES >

    < LINE_ID > 1 < / LINE_ID >

    < ELEMENT > POINT A1 < / ITEM >

    < / G_LINE >

    < G_LINES >

    < LINE_ID > 2 < / LINE_ID >

    A2 POINT < ITEM > < / ITEM >

    < / G_LINE >

    ...

    < / L_LINE_GROUP >

    I show the ITEM as a concatenated in a table field.

    as. QUESTION A1 POINT A2 A3...

    I tried..? for each: G_LINES? > <? G_LINES? > <? end foreach? > inside the cell, it prints inside the cell, but each element of the new line. I need to display as a concatenated string.

    Thanks for supporting me how in rtf.

    Thank you and best regards,

    Raja.

    The code of the cell can be

    This will ensure that the values are concatenated

  • How to display a field date null?

    We have a few million chronogram and former AAU transformed system and many dates were null. These appear as 01/01/53 (January 1, 1753) and requirements is to display spaces. It seems so simple but I can't think about how do and can't find that he documented in the forum anywhere. Any ideas?

    Bill

    Take a look in the database directly. Your migrated data will have the date in it. Clean data as Ryan mentioned a few posts ago. (Content Server does not display null values in the date "01/01/53" string, but as a vacuum.)

  • The data forms Web site - how to display the dimensions of all the columns?

    Hello

    I'm working on a data form. I took accounts in lines and period, year and scenario in my columns. The first pass is displayed correctly-> P #JAN. Y#@CUR. S #ACTUAL
    But when I used the second col-> P #FEB. Y#@CUR. S #ACTUAL and save my data form. I can see the year and only col1 scenario dimension. Col2: Only FEB appears without year and scenario. How can I spread the year and the other columns scenario, rather than display only in col1. Your help will be greatly appreciated. Thank you.

    If you use the standard Web in the workspace form tool, you can bring up the form in edit mode, select the Details tab and there is an option "Repeat the headers", Just check the box and you should be good to go.

    JOINT TASK FORCE

  • How to READ XML and display hirarechy and data in separate columns 2

    Hi, I have the following XML example and I need to extract the hirarechy and values separately. If the value is null, hirarechy must be displayed. Please advice!
    for example,.
    I want to output something this link

    NŒUD
    ---------------------------
    8. TEST4. FIVE
    8. TEST4. SIX
    8. TEST4. 7. TEST2. TWO
    8. TEST4. 7. TEST2. THREE



    VALUE
    ------------------------------------
    1

    5
    I test m


    example of XML data:

    <? XML version = "1.0"? >
    rowset <>
    < ROW >
    < 8 >
    < TEST4 >
    < 5 > 1 < / FIVE >
    < 6 / >
    < 7 >
    < TEST2 >
    < TWO > 5 < / TWO >
    test of m i < 3 > < / 3 >
    < 4 >
    < A > 26 March 12 < / ONE >
    < / OVEN >
    < / TEST2 >
    < / SEVEN >
    < / TEST4 >
    < TEST4 >
    < 5 > 1 < / FIVE >
    < SIX > 26 March 12 < / SIX >
    < 7 >
    < TEST2 >
    < TWO > 5 < / TWO >
    < 3 > 67 < / 3 >
    < 4 >
    < A > 26 March 12 < / ONE >
    < / OVEN >
    < / TEST2 >
    < / SEVEN >
    < / TEST4 >
    < / 8 >
    < / ROW >
    < / LINES >

    Thank you

    Published by: Saad at March 26, 2012 15:18

    What is xml_test in your example? his error on this one.

    This is a table of xmltype object I used to store your XML for my first tests.
    Sorry, I forgot to remove the part while testing with a variable binding in place.

    Try this one (pass your real xmltype variable instead of xmltype(:xmldoc)):)

    SELECT x.node_id
         , x.node_value
    FROM XMLTable(
         'declare function local:getChildren($e as node(), $pID as xs:string?) as element()*
          {
            for $i in $e/(child::*|attribute::*)
            let $ID := if ($pID) then concat($pID,".",name($i)) else name($i)
            return element r
            {
              attribute is_leaf {empty($i/child::*)}
            , element node_id {$ID}
            , element parent_node_id {$pID}
            , element node_name {name($i)}
            , if ($i instance of attribute())
                then ( element node_value {data($i)}, element node_kind {"attribute"} )
                else ( element node_value {$i/text()}, element node_kind {"element"} )
            }
            | local:getChildren($i,$ID)
          }; (: :)
          local:getChildren($d/ROWSET/ROW,())'
          passing xmltype(:xmldoc) as "d"
          columns node_id         varchar2(100)   path 'node_id'
                , node_name       varchar2(30)    path 'node_name'
                , node_value      varchar2(2000)  path 'node_value'
                , parent_node_id  varchar2(100)   path 'parent_node_id'
                , node_kind       varchar2(30)    path 'node_kind'
                , is_leaf         varchar2(5)     path '@is_leaf'
         ) x
    WHERE is_leaf = 'true'
    ;
    
  • How to display all the data using several parameters?

    Hi all
    I used a query as follows to display the data in a report:

    Select col1, col2 / / col1 and col2 are columns of tabale tab1
    of tab1
    where
    tab1.Col1 =
    (case when: P_COL1 IS NOT NULL then / /: P_COL1 IS a USER SETTING to EQUAL COL1)
    : ANOTHER P_COL1 tab1.col1
    end)

    AND TAB1. COL3 =
    (case when: P_COL3 IS NOT NULL then / /: P_COL3 IS a USER SETTING to EQUAL COL3)
    : ANOTHER P_COL3 tab1.col3
    end)

    The problem is when I run the report with the values of parameters or not, it shows the data that is not null for col1 and col3.
    That is when the value of col1 or col3 is zero the report would not return this record!
    I want the report to show all the data not just the values that is not null.
    How to do this?

    Men,

    ( :p_col1 is null or ( :p_col1 = tab1.col1 ) )
    and
    ( :p_col2 is null or ( :p_col2 = tab1.col2 ) )
    and
    ( :p_col3 is null or ( :p_col3 = tab1.col3 ) )
    
    etc.
    

    Kurz

Maybe you are looking for

  • How to create the 2d cursor?

    How can I create slider 2d, something like the square with the point of the mouse controlled inside in the upper left corner in the photo, so I don't need to use 2 separate cursors for x and y?

  • Fluke 6100 driver error

    I have a quesiton about the fluke 6100 driver.  The first time I run my program, the initialization of the pilot will give me an error, but if I run the program again, the error will disappear.  Why is this? Yik

  • Still access Youtube and Facebook when both are blocked?

    Why does show that my child is still access youtube and facebook when both are blocked?

  • bootable mSata SSD on V5 573 G

    Hello I am owner of a V5 74508G1Takk 573G (with Geforce 720 m) Given that it is a bit different from the other 573G I see here (with Geforce 750 m), I would like to ask for confirmaton I have 1 x mSata. Also, I tried if I can do the mSata SSD bootabl

  • Connect to a card with two 8 pins Aurora R1

    I think that this was discussed years ago, but I forgot. My R1 has each taken video connector one 6 pins and a connector 8-pin card. The 980ti that I'm looking requires two connections of 8 pins. Can I plug both plugs 8 separate pins in the ti GTX 98