Query for data transformation

I have a table as below                                           
ID     Label     Value                              
1     L1     V1                              
1     L2     V2                              
1     L3     V3                              
2     L1     V1                              
2     L2     V2                              
2     L3     V3                              
2     L4     V4                              
3     L1     V1                              
3     L2     V2                              
3     L3     V3     
  I have to write a SQL qry to show result as below                                           
ID     Label1     Value1     Label2     Value2     Label3     Value3     Label4     Value4
1     L1     V1     L2     V1     L3     V3            
2     L1     V1     L2     V1     L3     V3     L4     V4
3     L1     V1     L2     V1     L3     V3      
Kindly share SQL.      

{noformat}*sigh*{noformat}
This question is asked almost every day. It's a shame people don't learn how to search the forums, or just look for similar things.
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 1 as id, 'L1' as label, 'V1' as value from dual union all
  2             select 1, 'L2', 'V2' from dual union all
  3             select 1, 'L3', 'V3' from dual union all
  4             select 2, 'L1', 'V1' from dual union all
  5             select 2, 'L2', 'V2' from dual union all
  6             select 2, 'L3', 'V3' from dual union all
  7             select 2, 'L4', 'V4' from dual union all
  8             select 3, 'L1', 'V1' from dual union all
  9             select 3, 'L2', 'V2' from dual union all
10             select 3, 'L3', 'V3' from dual)
11  -- END OF TEST DATA
12  select id
13        ,max(decode(rn,1,label)) as "Label1"
14        ,max(decode(rn,1,value)) as "Value1"
15        ,max(decode(rn,2,label)) as "Label2"
16        ,max(decode(rn,2,value)) as "Value2"
17        ,max(decode(rn,3,label)) as "Label3"
18        ,max(decode(rn,3,value)) as "Value3"
19        ,max(decode(rn,4,label)) as "Label4"
20        ,max(decode(rn,4,value)) as "Value4"
21  from (select id, label, value, row_number() over (partition by id order by label) as rn from t)
22* group by id
SQL> /
        ID La Va La Va La Va La Va
         1 L1 V1 L2 V2 L3 V3
         2 L1 V1 L2 V2 L3 V3 L4 V4
         3 L1 V1 L2 V2 L3 V3
SQL>

Similar Messages

  • Cm:select content query for date

    Hi,
    does anyone know how to form the query in the cm:select tag for dates.
    i want to do something like this but it does not work that way:
    <cm:select query="type = 'news' && date > 05.10.2002" ...>
    thanks for any help.

    Please post this to the Portal newsgroup.
              ronald ploeger wrote:
              > Hi,
              >
              > does anyone know how to form the query in the cm:select tag for dates.
              >
              > i want to do something like this but it does not work that way: <cm:select query="type
              > = 'news' && date > 05.10.2002" ...>
              >
              > thanks for any help.
              Regards,
              Ann
              Developer Relations Engineer
              BEA Support
              

  • Ms access 2007 between query for date

    Dear All,
    I am using the below query to fetch records from a table between two dates
    select * from tablename where Format([VisitDate],"Short Date") >=Format(#01/10/2014#,"Short Date") and Format([VisitDate],"Short Date") <=Format(#31/10/2014#,"Short Date")
    I want records between 1st Oct to 31st Oct only, but the above query shows Nov and December data also. Please let me know where I am going wrong.
    Regards,
    Noor 
    Thanks & Regards, Noor Hussain

    The Format function returns a string expression, so the comparison is on that basis not on the date value.  You do not need to worry about the format at all as the date/time data type in Access is implemented as a 64 bit floating point number. 
    You can see it in whatever date/time format you wish, but the underlying value is always the same.  When you include a date literal in an SQL statement or in VBA code it must be either in US short date format (mm/dd/yyyy), or in an internationally unambiguous
    format.  The ISO standard format for date notation of YYYY-MM-DD is a good choice.  So you query would be:
    SELECT *
    FROM tablename
    WHERE VisitDate  >=  #2014-10-01#
    AND VisitDate < #2014-11-01#;
    Note that the range is defined as on or after the start date and before the day following the end date.  This ensures that all relevant rows are returned.  As there is no such thing in Access as a 'date value', but only a 'date/time value' it is possible
    that a 'date' of 31 October 2014 could have a non-zero time of day element unless you have taken steps in the table definition to specifically exclude values with a non-zero time of day.  Such date/time values would not fall within a range ending <=
    #2014-10-31#, so would not be returned by the query.  Defining the end of the range with < #2014-11-01# ensures that such rows are returned.
    Ken Sheridan, Stafford, England

  • Query for data

    Hi all, i am trying to write a query for a specific scenario using analytic functions.
    i have a table that has data in week basis. here is some sample data
    id date value
    1 1/4/10 A
    1 1/11/10 B
    1 1/18/10 C
    2 ....
    2 ....
    each date represent the beginning of the week. i have another table that contains calendar dates that include day of the week excluding weekends and holidays.
    example data
    id date
    1 1/4/10
    1 1/5/10
    1 1/6/10
    1 1/7/10
    1 1/8/10
    1 1/11/10
    1 ...... SO ON
    as you can see 1/1/10, 1/2, 1/3 are not present because they are either holidays or weekends.
    what i want to do is join this two tables by id and the output should be the following
    1 1/4/10 A
    1 1/5/10 A
    1 1/6/10 A
    1 1/7/10 A
    1 1/8/10 A
    1 1/11/10 B
    1 1/12/10 B
    1 1/13/10 B
    1 1/14/10 B
    1 1/15/10 B
    and so on. so as you can see. i am converting the week table (first table) into day basis. i tried to use analytic function but i was not very successful since i am new to them. any help will be appricatiate. provide sample query if possible. thanks a lot

    Hi,
    What if the week crosses over 2 months.
    Fo example March the last week starts on 29 and has 1st apr and 2nd apr in the same week.Would you consider those?
    If not here is one way of doing it.
    with t1 as (
                select 1 id,DATE '2010-03-01' dt,'A' val from dual union all
                select 1,DATE '2010-03-08','B' from dual union all
                select 1,DATE '2010-03-15','C' from dual UNION ALL
                select 1,DATE '2010-03-22','D' from dual    UNION ALL
                select 1,DATE '2010-03-29','E' from dual  
         t2 as (
                select 1 id,DATE '2010-03-01' dt from dual union all
                select 1,DATE '2010-03-02' from dual union all
                select 1,DATE '2010-03-03' from dual union all
                select 1,DATE '2010-03-04' from dual union all
                select 1,DATE '2010-03-05' from dual union all
                select 1,DATE '2010-03-08' from dual union all
                select 1,DATE '2010-03-09' from dual union all
                select 1,DATE '2010-03-10' from dual union all
                select 1,DATE '2010-03-11' from dual union all
                select 1,DATE '2010-03-12' from dual UNION ALL
                select 1,DATE '2010-03-15' from dual UNION ALL
                select 1,DATE '2010-03-16' from dual UNION ALL           
                select 1,DATE '2010-03-17' from dual UNION ALL
                select 1,DATE '2010-03-18' from dual UNION ALL
                select 1,DATE '2010-03-19' from dual UNION ALL
                select 1,DATE '2010-03-22' from dual UNION ALL
                select 1,DATE '2010-03-23' from dual UNION ALL                                               
                select 1,DATE '2010-03-24' from dual UNION ALL                                                           
                select 1,DATE '2010-03-25' from dual UNION ALL                                                           
                select 1,DATE '2010-03-26' from dual UNION ALL                                                         
                select 1,DATE '2010-03-29' from dual UNION ALL
                select 1,DATE '2010-03-30' from dual UNION ALL
                select 1,DATE '2010-03-31' from dual UNION ALL
                select 1,DATE '2010-04-01' from dual UNION ALL  
                select 1,DATE '2010-04-01' from dual                                )
               SELECT DISTINCT a.ID,b.dt,a.val,to_char(b.dt,'IW') FROM t1 a,t2 b WHERE a.ID=b.ID
               AND to_char(a.dt,'MON')=to_char(b.dt,'MON')
               AND to_char(a.dt,'IW')=to_char(b.dt,'IW')
               ORDER BY val,dtCheers!!!
    Bhushan

  • Selction query for date

    i have a interface there user can enter two dates . in my servlet program i am getting it as string by using request .get parameter. i wanan to know how to write sql query for selecting data from database with between clause

    //for example you are getting the date format like 17-Jul-2006 as String
    String strDate1 = "17-Jul-2006";//request.getParameter("date1");
    String strSQL = "SELECT SYSDATE from dual
    WHERE SYSDATE - 10 > to_date('"+date1 +"','dd-mm-yyyy')";
    Hope this example will help you!!!
    Regards,
    AfTaB

  • Query for date range?  DPL

    Sorry if this has been answered before, but I couldn't find the answer. I'm new to the DPL and was trying to find out how to query for objects that fall within a "date range". If I have an object that has a field "effective date", I would like to query for a list of objects that fall between a date range. Can I do this with DPL?
    thanks,
    John

    Hi,
    Yes, the DPL can be used to iterate over the entities where a given date field D falls with a specified date range. To do this, you define D as a @SecondaryKey, create a SecondaryIndex for it, and get a cursor for the specified range using one of the SecondaryIndex.entities() methods. Be sure to close the cursor.
    See the Key Ranges section in this class description:
    http://www.oracle.com/technology/documentation/berkeley-db/je/java/com/sleepycat/persist/EntityCursor.html
    Dates are treated as long values, so a range of Date keys is no different that a range of long keys. Date and long are both "simple types" according to the DPL definition.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Query for date range? JE

    Hi,
    I have seem some posts on the JE forum regarding quering for date range, but it is mostly using DPL.
    Is there any way to do that using the JE API
    Thanks,
    Mohammad

    Hi Mohammad,
    A date range query can be performed as a key range query. There's nothing special about dates except that you'll want to use a key binding that gives a meaningful sort order. If you're representing your dates in milliseconds, then a LongBinding (in com.sleepycat.bind.tuple) will work well. In general, use tuple bindings for keys, because they provide a meaningful sort order.
    To perform a range query, this FAQ has some hints:
    http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html#28
    On range searches in general, they can be done with Cursor.getSearchKeyRange or with the SortedSet.subSet and SortedMap.subMap methods, depending on whether you are using the base API or the Collections API. It is up to you which to use.
    If you use Cursor.getSearchKeyRange you'll need to call getNext to iterate through the results. You'll have to watch for the end range yourself by checking the key returned by getNext. This API does not have a way to enforce range end values automatically.
    If you use the Collections API you can call subMap or subSet and get an Iterator on the resulting collection. That iterator will enforce both the beginning and the end of the range automatically.
    Does this answer your question?
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Query for Date Manipulation

    Hi,
    I have a requirement where given a date, I need to get the range from the given date and the last date of the subsequent month.
    For example if the given date is 20070517(YYYYMMDD), I need to fetch records within the range of this date that is 20070517 and 20070630.
    Can someone help me in forming a query for this.
    thanks in advance.
    Harish

    maybe this can work:
    SQL> select sysdate given_date, last_day(add_months(sysdate,1)) next_month
      2  from dual;
    GIVEN_DAT NEXT_MONT
    17-MAY-07 30-JUN-07well you just do the WHERE clause, but the idea is there.

  • SQL Query for Date field updation

    I want a query from u.. Hope u help me with a
    solution soon..
    My Q: I want to update a date field in Oracle
    database. But the condition is that i shouldnt change
    the hours, minutes & seconds of the date field.
    generally , if we update the date field then it takes
    the default values for hours, min's & sec's to
    00:00:00.
    EX : if we have a value 21-SEP-2002 04:54:44 in a date
    field. I want to update it to 22-SEP-2002 04:54:44.
    But it updates to 22-sep-2002 00:00:00 if we use
    UPDATE command.

    Use a PreparedStatement:
    PreparedStatement ps = conn.prepareStatement("SELECT * FROM TEMP WHERE TDATE > ? AND TDATE < ?");
    // note: month numbers start at 0, so 1 is february
    GregorianCalendar c1 = new GregorianCalendar(2002, 1, 11, 11, 0);
    GregorianCalendar c2 = new GregorianCalendar(2002, 1, 18, 22, 0);
    Date d1 = c1.getTime();
    Date d2 = c2.getTime();
    java.sql.Timestamp sqlDate1 = new java.sql.Timestamp(d1.getTime());
    java.sql.Timestamp sqlDate2 = new java.sql.Timestamp(d2.getTime());
    ps.setTimestamp(1, sqlDate1);
    ps.setTimestamp(2, sqlDate2);
    ResultSet rs = ps.executeQuery();
    // get results from the result setJesper

  • Select query for dates

    Hi All,
    Could you please help with a SELECT query to retrieve the following dates ...
    sysdate - 1
    sysdate,
    sysdate + 1
    Sorry for the miscommunication .. I wanted these dates in a single column as given below
    21-May-2012
    22-May-2012
    23-May-2012
    Regards,
    Jitesh Gurnani
    Edited by: Jitesh Gurnani on May 22, 2012 2:53 AM

    >
    Sorry for the miscommunication .. I wanted these dates in a single column as given below
    21-May-2012
    22-May-2012
    23-May-2012
    >
    select sysdate - level + 2
      from dual
    connect by level <= 3
    order by 1Edited by: Paul Horth on 22-May-2012 02:59

  • SQL query for date & time interval

    Hello everyone,
    there is my problem
    I have to make a search for events that are taking place during inserted date & time .
    There's the table structure:
    event
    datefrom
    dateto
    timefrom
    timeto
    The problem is, when I try:
    select * from xyz where datefrom <= inserted_date and dateto >= inserted_date and timefrom <= inserted_time and timeto >= inserted time;
    then I don't get back all records.
    eg: user inserts date = 10.10.2010 and time 10:00 and in the table is event [abc 11:00 9.10.2010 -> 09:00 11.10.2010] stored following way:
    event         abdc
    datefrom   09.10.2010
    dateto        11.10.2010
    timefrom    11:00
    timeto         09:00
    => this event won't be found, because the sql logic compares only single parameters and not their context.
    Do you have any idea, how to solve this issue?
    Thank you.
    Lukas

    Hello Hubert,
    thank you very much for your proposal, but your code makes the same select as mine (but in a more user friendly look :).
    Table:
    datefrom 09.10.2010
    dateto 11.10.2010
    timefrom 11:00
    timeto 09:00
    Event date = 10.10.2010 and time 10:00.
    Your query:
    select * from xyz where 10.10.2010 between 09.10.2010 and 11.10.2010 (that's so far ok) and 10:00 between 11:00 and 9:00 (no return there, because 10:00 doesn't lie within interval 11:00 -> 9:00... actually no value lies there) ;
    Don't you have any other idea?
    Thank you
    Lukas

  • SQL Query for DATE

    In my Jsp program, i have 3 schemes, one for 1 month, second for 3 month, and third for 12 month.
    Now an user can create his account and select any of the 3 schemes, what i want is that in my database table there are two columns one is tha startdate colume which holds data for the date posted, ie, current date, and the other column is the enddate which holds data for the expiry date depending on the schemes selected....
    What i want is that when a user register for an account his startdate is the present date and i want a query which automatically calculates the enddate keeping in mind the scheme and update the table with the derived result.
    Thanx :banghead:

    Check out the Calendar API, specially the add method, e.g, for adding 3 days to some date
                Calendar cal = Calendar.getInstance();
                cal.setTime(currentTime);//The current time
                cal.add(Calendar.DATE, 3);//Add 3 days to the current timeCheck the api for adding months instead of days,
    regards,
    Manuel Leiria

  • SQL query for date picker

    On a reports page there are two 2 date picker items ( a datefrom and a dateto) along with a text field with autocomplete item
    When the page loads the following query is called
    SELECT
    "COL1",
    "COL2",
    "COL3",
    from "TABLE"
    WHERE MYDATES BETWEEN :DATEFROM AND :DATETO
    Which returns no records as no dates have been selected.
    How can I alter this so the WHERE clause on the date item searches is called only if and when the dates are chosen, and by default all records are shown.
    The other related issue is when I have selected a from and to date and search when I go back into the report view page after viewing other pages in the apex app, the form fields are still populated, how can I clear the session down for these fields when the user leaves the page?
    Hope this all makes sense?

    To_date('01.01.2100', 'dd.mm.yyyy') is going to give wrong results on 02.01.2100 :D
    A solution (maybe there is a cleaner one...) :
    WHERE
    ((:DATEFROM IS NOT NULL AND mydates >= :DATEFROM) OR :DATEFROM IS NULL)
    AND
    ((:DATETO IS NOT NULL AND mydates <= :DATETO) OR :DATETO IS NULL)You can change the "No data found" message by modifiying the "When No Data Found Message" report attribute.
    EDIT : And for the 2nd issue, Alex is right, but also be aware that Firefox retains form element values on page refresh, you have to switch the "Form Auto Complete" page security attribute to "Off" if you don't want to retain form element values.
    Edited by: Yann39 on 27 juin 2012 06:30

  • Query for data input into IncoCube (Non Integrated Planning)

    Hello Gurus,
    i was trying to search over the internet how to make a query ready for input, but without using integrated planning, but no luck.
    I want to make a bex query (specific form) which could be filled with data by simple user, and then on button click sent to BW InfoCube.
    Is it at all possible or not?
    Thanks and Regards

    Hi,
    Thanks for quick responce.
    So basically what you are saying is that only IP anables me to enter the data through BEX.
    Regards
    Laurynas

  • Query for date generating the months as well

    Hi Folks
    I need your help to resolve th query below
    I need to generate the sql query
    example
    YEAR MONTH count(EMPNO)
    1981 JAN 0
    FEB 2
    MAR
    DEC
    I need to generate all the months and count of employee being hired for that month,where the month without any emp being hired should show as 0

    Or perhaps...
    SQL> WITH t AS (SELECT TO_DATE('01/01/2008','dd.mm.yyyy') AS dt, 1 AS eno FROM dual UNION ALL
      2             SELECT TO_DATE('01/01/2008','dd.mm.yyyy') AS dt, 2 FROM dual UNION ALL
      3             SELECT TO_DATE('01/02/2008','dd.mm.yyyy') AS dt, 3 FROM dual UNION ALL
      4             SELECT TO_DATE('01/06/2008','dd.mm.yyyy') AS dt, 4 FROM dual UNION ALL
      5             SELECT TO_DATE('01/03/2007','dd.mm.yyyy') AS dt, 3 FROM dual UNION ALL
      6             SELECT TO_DATE('01/05/2007','dd.mm.yyyy') AS dt, 4 FROM dual UNION ALL
      7             SELECT TO_DATE('01/02/2008','dd.mm.yyyy') AS dt, 5 FROM dual UNION ALL
      8             SELECT TO_DATE('01/12/2008','dd.mm.yyyy') AS dt, 6 FROM dual)
      9  -- END OF TEST DATA
    10  SELECT EXTRACT(year FROM md.md) as year, EXTRACT(month FROM md.md) as month, count(t.dt) as cnt
    11  FROM (select add_months(min_date,rownum-1) as md
    12        from (select min(trunc(dt,'MM')) as min_date, max(trunc(dt,'MM')) as max_date from t)
    13        connect by rownum <= months_between(max_date,min_date)+1) md
    14       LEFT OUTER JOIN t ON (trunc(t.dt) = md.md)
    15  GROUP BY EXTRACT(year FROM md.md), EXTRACT(month FROM md.md)
    16  ORDER BY 1,2
    17
    SQL> /
          YEAR      MONTH        CNT
          2007          3          1
          2007          4          0
          2007          5          1
          2007          6          0
          2007          7          0
          2007          8          0
          2007          9          0
          2007         10          0
          2007         11          0
          2007         12          0
          2008          1          2
          2008          2          2
          2008          3          0
          2008          4          0
          2008          5          0
          2008          6          1
          2008          7          0
          2008          8          0
          2008          9          0
          2008         10          0
          2008         11          0
          2008         12          1
    22 rows selected.
    SQL>

Maybe you are looking for

  • Windows is not syncing ipod to itunes...

    So I can plug in my ipod into another computer and it'll work, and I can plug a different ipod into my computer and it'll work. I've tried uninstalling and reinstalling itunes, trying different cords and usb ports. I think I accidently hit the button

  • Internal error while checking object Message Mapping...

    Error details: ERROR com.sap.aii.utilxi.swing.toolkit.ExceptionDialog: Throwable Thrown: MESSAGE ID: com.sap.aii.ib.server.cmpl.CompilerException <b>com.sap.aii.ib.core.mapping.exec.ExecuteException: Compilation process error : Not enough space</b>  

  • White screen or green screen question

    hi i have a series of interviews coming up...will shoot 1080.  I like the nice clean look of white for the background. Question is whether to shoot with white backdrop or green screen and key white in post.  Here is my issue: I want to use part of th

  • From Podcasts to MacBook

    Is any way to copy files from Podcasts to MacBook without iPod ? The problem is,friend of my,ask me for some stuff from Podcasts. He can't have it on his really old PC. And I don't want to risk his 80 Gig iPod full of important stuff... So,any ideas

  • Print Selection

    I'm running Tiger 10.4 with an HP Officejet 6310 printer. I've had no problems with installing and using the printer. But I sure miss the HP GUI that used to display in the windows OS that would allow me to print a selection from a web page, among a