Ordering data based on 2 columns

Hi,
I have a table as below
Name1
Age1
Name2
Age2
a
10
a
15
a
10
a
5
c
20
b
25
e
25
c
18
f
30
d
100
I want to order the table based on both (name1 and name2) and then after on age1 and age2.
the resultant data i require is as below
Name1
Age1
Name2
Age2
null
null
a
5
a
10
null
null
a
10
null
null
null
null
a
15
null
null
b
25
null
null
c
18
c
20
null
null
null
null
d
100
e
25
null
null
f
30
null
null
I am able to get the data by performing an outer join but unable to sort in this fashion. Please suggest.

Another way
with
temp as
(select 'a' name1,10 age1,'a' name2,15 age2 from dual union all
select 'a',10,'a',5 from dual union all
select 'c',20,'b',25 from dual union all
select 'e',25,'c',18 from dual union all
select 'f',30,'d',100 from dual
select *
  from (select name1,age1
          from temp
       ) x
       full outer join
       (select name2,age2
          from temp
       ) y
    on x.name1 = y.name2
   and x.age1 = y.age2
order by coalesce(x.name1,y.name2),coalesce(x.age1,y.age2)
NAME1
AGE1
NAME2
AGE2
a
5
a
10
a
10
a
15
b
25
c
18
c
20
d
100
e
25
f
30
Regards
Etbin

Similar Messages

  • Eliminate Data based on a column

    Hello All,
    I am in very weird situation. I have to filter data based on a column. For example, my data is like :
    Col1       Col2        Col3       Col4
    A1         A              B           C
    A2         A              B            D
    A3         A              B            E
    F           G              H             I
    J            K               L             M
    I have to filter data based on col1 which has the maximum if Col2 and Col3 have same value. So the o/p of above data will be  if (A3> A2 > A1) as  Col2 and Col3 have same value A and B:
    Col1       Col2            Col3       Col4
    A3             A              B            E
    F              G               H             I
    J               K               L             M
    Please suggest.

    Hi,
    One way to do that is a Top-N Query .  Since you didn't post your table, I'll use scott.emp to illustrate.  Ename, deptno, job and hiredate in scott.emp correspond to col1, col2, col3 and co4l (respectively) in your table.
    WITH got_r_num AS
    SELECT ename, deptno, job, hiredate
    , ROW_NUMBER () OVER ( PARTITION BY  deptno, job
                   ORDER BY      ename   DESC
           ) AS r_num
    FROM scott.emp
    SELECT ename, deptno, job, hiredate
    FROM got_r_num
    WHERE r_num  = 1
    The query above displays only 1 row for each distinct combination of deptno and job, the row with the last ename.

  • How to filter the Rest Api data based on Taxanomy columns

    Hi Everyone,
    We are using SharePoint2010 Standard Edition.
    I wanted get the library details through REST Api. I am using as below:
    https://SiteUrl/_vti_bin/listdata.svc/Documents?$filter=Title eq 'SharePointDoc'
    Here I am able to get the info regarding "SharePointDoc". But when I am trying to get the details from Taxonomy filter, it didn't.
    Can anyone please tell me how can we filter based on Taxanomy fields.
    Thanks in Advance
    Krishnasandeep

    Hi,
    I understand that you wanted to filter the Rest Api data based on Taxanomy columns.
    Per my knowledge, in SharePoint 2010 , not all types of column are available via REST, most annoyingly managed metadata columns are amongst this group of unsupported column types.
    However, in SharePoint 2013, we can filter list items based on taxonomy (managed metadata) columns.
    Taxonomy fields can be now called via REST API using CAML query in REST calls.
    Here is a great blog for your reference:
    http://www.cleverworkarounds.com/2013/09/23/how-to-filter-on-a-managed-metadata-column-via-rest-in-sharepoint-2013/comment-page-1/
    You’d better to change the REST calls and the CAML query to check whether it works in SharePoint 2010.
    More information:
    http://platinumdogs.me/2013/03/14/sharepoint-adventures-with-the-rest-api-part-1/
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How to restrict a table with its set of data based on a column value in it?

    Hi,
    I have a scenario in which I have to show a set of data of a pivot table by restricting data based on a column value. I am creating BIP report whose source is from BIA ie.RPD. Based on a column value I want to restrict the data being displayed in the table. Since I also want the hidden data in the first table to be displayed in another table in the same report I cannot restrict the data at the query level i.e at RPD or at BIA. For this reason I used
    <?xdofx:if saw3_ = 1?>
    the pivot table
    <?end if?>
    But it does not restrict any data.
    Also I tried using the if condition inside the table before the row level looping happens. But no good show even then.
    How can I forgo this problem?
    Regards,
    The MM

    Hi,
    See : http://download.oracle.com/docs/cd/E12096_01/books/PubUser/T421739T481157.htm#4535373 regarding column and row.
    Regards,
    Colectionaru

  • How to split the data based on one column

    Dear All,
    I have the table data like this.
    type quantity revenue_mny count country
    a 10           10          2 India
    a 20          12          3 India
    b 30          15          1 India
    a 35          20          2 US
    b 20          10          1 US
    b 60          15          1 US
    I woulkd like to split the date based on type column.
    For each country, for Type "a" get the sum of revenue count quanity ans same for b
    and all shuld come in on row for each country.
    output should be like
    country revenue_mny(For a) quantity(for a) count(For a) revenue_mny(for b) quantity(for b) count(For b)
    India 22 30 5 15 30 1
    US 20 35 2 25 80 2
    I tried the below query . its not splittng the date for each country in one row.
    select country,
    sum(case when type='a') then revenue_mny else 0 end ) revenue_mny_a,
    sum(case when type='b' then revenue_mny else 0 end ) revenue_mny_b
    sum(case when type='a' then quantity else 0 end) quantity_a,
    sum(case when type='b' then quantity else 0 end) quantity_b from
    test
    group by country
    Please need your helo

    Like this?
    with t as
    select 'a' type, 10 quantity, 10 revenue_mny, 2 cnt, 'India' country from dual union all
    select 'a', 20, 12, 3, 'India' from dual union all
    select 'b', 30, 15, 1, 'India' from dual union all
    select 'a', 35, 20, 2, 'US' from dual union all
    select 'b', 20, 10, 1, 'US' from dual union all
    select 'b', 60, 15, 1, 'US' from dual
    select country,
    sum(case when type='a' then revenue_mny else 0 end ) revenue_mny_a,
    sum(case when type='a' then quantity else 0 end) quantity_a,
    sum(case when type='a' then cnt else 0 end) cnt_a,
    sum(case when type='b' then revenue_mny else 0 end ) revenue_mny_b,
    sum(case when type='b' then quantity else 0 end) quantity_b ,
    sum(case when type='b' then cnt else 0 end) cnt_b
    from t
    group by country;result:
    COUNTRY  REVENUE_MNY_A QUANTITY_A CNT_A REVENUE_MNY_B QUANTITY_B CNT_B
    India    22            30         5     15            30         1
    US       20            35         2     25            80         2Or you can do it with a decode instead of case. The result will be the same:
    with t as
    select 'a' type, 10 quantity, 10 revenue_mny, 2 cnt, 'India' country from dual union all
    select 'a', 20, 12, 3, 'India' from dual union all
    select 'b', 30, 15, 1, 'India' from dual union all
    select 'a', 35, 20, 2, 'US' from dual union all
    select 'b', 20, 10, 1, 'US' from dual union all
    select 'b', 60, 15, 1, 'US' from dual
    select country,
    sum(decode(type,'a',revenue_mny,0)) revenue_mny_a,
    sum(decode(type,'a',quantity,0)) quantity_a,
    sum(decode(type,'a',cnt,0)) cnt_a,
    sum(decode(type,'b',revenue_mny,0)) revenue_mny_b,
    sum(decode(type,'b',quantity,0)) quantity_b,
    sum(decode(type,'b',cnt,0)) cnt_b
    from t
    group by country;(I changed tablename from TEST to T and columnname from COUNT to CNT, because you should not use reserved words as tablename or columnname.)
    Edited by: hm on 09.10.2012 06:17

  • How to display data based on two columns in Apex calendar?

    I have a table for holiday details with 2 date columns...from-date and a to-date. I need to display the name of the person for the date range they have specified. For Ex if i applied for leaves from may 1 to may 4...the calendar should display my name for 4 dates i.e may1,2,3 and 4
    I am new user in apex and still trying new things. Please help me achieve this.

    Swetha
    I created an application using Apex. It is a calendar application to show events that are happening. I ran into an issue with it
    If there is an event that occurs during an interval like August15 - August22, the event is shown only on August15, which is the first day of the event. I would like to show it in all days from August15-22.
    Here are the items coming from the page
    event_id number,
    employee_id number
    date_from date,
    date_to date,
    due_date date,
    act_id number,
    act_loc varchar2,
    reminder varchar2,
    frequency varchar2,
    division varchar2,
    event_status varchar2
    I am looking to write a process / procedure where it can show the same event on all the days it is occurring
    Thanks in advance
    Latha

  • Search for columnName and Split data based on that column name

    Hi All,
    I have a table with one column, lets say Notes of datatype varchar(max).
    Source Date:
    Notes
    ABC:123:XYZ Dept:IT NameID:1 Name:Tom Hummer Date:04/12/2004
    456789:CDEF:ADEF
    CBD:12/12/2000:ZXCV Dept:HR NameID:1 Name:Sam Dope Date:06/17/2005
    I want Output should look like below. It should split data at 'Dept:' and 'Name:' I need SQl code  for SQL Server 2008 R2
    Output:
    Notes
    Dept:IT Name:Tom Hummer
    Dept:HR Name:Sam Dope
    Thanks,
    RH
    sql

    Hello,
    Please refer to the following statements:
    create table notes (note varchar(max));
    insert into notes values
    ('ABC:123:XYZ Dept:IT NameID:1 Name:Tom Hummer Date:04/12/2004'),
    ('456789:CDEF:ADEF'),
    ('7890:RST:QWER Dept:Sales NameID:2 Name:Mike Kule'),
    ('CBD:12/12/2000:ZXCV Dept:HR NameID:1 Name:Sam Dope Date:06/17/2005')
    select case
    when charindex('Name:',note)>0 and charindex('Date:',note)>0
    then SUBSTRING(note,charindex('Name:',note)-1,charindex('Date:',note)-charindex('Name:',note))
    when charindex('Name:',note)>0 and charindex('Date:',note)=0
    then SUBSTRING(note,charindex('Name:',note)-1,len(note)-charindex('Name:',note))
    end as name
    from notes
    where charindex('Name:',note)>0
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • How to achieve grouping of data based on one column

    Hello PL/SQL Gurus/experts,
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version
    I have following table -
    DROP TABLE T2;
    create table T2(Manager,Employee) as select
    'Nikki','Ram' from dual union all select
    'Nina', 'Rita' from DUAL union all select
    'Mike', 'Radha' from dual union all select
    'Michael', 'Ratnam' from DUAL union all select
    'Hendi', 'Ratna' from dual union all select
    'Robert', 'Raman' from dual union all select
    'Maria', 'Rolly' from dual union all select
    'Kistrien', 'Rachna' from dual union all select
    'Andrew', 'Ritvik' from dual union all select
    'Emma', 'Ramesh' from dual union all select
    'Andy', 'Ranpal' from dual union all select
    'Brandy', 'Raunak' from dual union all select
    'Nikki','Shyam' from dual union all select
    'Nina', 'Sita' from DUAL union all select
    'Mike', 'Sadhna' from dual union all select
    'Michael', 'Satnam' from DUAL union all select
    'Hendi', 'Satna' from dual union all select
    'Robert', 'Samar' from dual union all select
    'Maria', 'Sameer' from dual union all select
    'Kistrien', 'Samrachna' from dual union all select
    'Andrew', 'Satvik' from dual union all select
    'Emma', 'Somesh' from dual union all select
    'Andy', 'Sonpal' from dual union all select
    'Brandy', 'Samar' from dual union all select
    'Emma', 'Piyush' from dual union all select
    'Andy', 'Pavan' from dual union all select
    'Brandy', 'Paramjeet' from dual;Expected output -
    Manager          Employee
    Nikki
              Ram
              Shyam
    Nina           Rita
              Sita
    Mike           Radha
              Sadhna
    Michael      Ratnam
              Satnam
    Hendi           Ratna
              Satna
    Robert          Raman
              Samar
    Maria          Rolly
              Sameer
    Kistrien     Rachna
              Samrachna
    Andrew          Ritvik
              Satvik
    Emma          Ramesh
              Somesh
              Piyush
    Andy          Ranpal
              Sonpal
              Pavan
    Brandy          Raunak
              Samar
              ParamjeetI thank to all of you in advance for your valuable time and inputs

    In SQL, something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  select case when row_number() over (partition by emp.manager order by employee) = 1 then
      2           mgr.manager
      3         else
      4           null
      5         end as manager
      6        ,emp.employee
      7  from (select distinct manager from t2) mgr
      8       join t2 emp on (mgr.manager = emp.manager)
      9* order by mgr.manager, emp.employee
    SQL> /
    MANAGER  EMPLOYEE
    Andrew   Ritvik
             Satvik
    Andy     Pavan
             Ranpal
             Sonpal
    Brandy   Paramjeet
             Raunak
             Samar
    Emma     Piyush
             Ramesh
             Somesh
    Hendi    Ratna
             Satna
    Kistrien Rachna
             Samrachna
    Maria    Rolly
             Sameer
    Michael  Ratnam
             Satnam
    Mike     Radha
             Sadhna
    Nikki    Ram
             Shyam
    Nina     Rita
             Sita
    Robert   Raman
             Samar
    27 rows selected.If you want the managers on their own row with the employees underneath then you'll have to fudge it.
    SQL> ed
    Wrote file afiedt.buf
      1  select case when row_number() over (partition by emp.manager order by employee nulls first) = 1 then
      2           mgr.manager
      3         else
      4           null
      5         end as manager
      6        ,emp.employee
      7  from (select distinct manager from t2) mgr
      8       join
      9       (select distinct manager, null as employee from t2
    10        union all
    11        select manager, employee from t2
    12       ) emp on (mgr.manager = emp.manager)
    13* order by mgr.manager, emp.employee nulls first
    SQL> /
    MANAGER  EMPLOYEE
    Andrew
             Ritvik
             Satvik
    Andy
             Pavan
             Ranpal
             Sonpal
    Brandy
             Paramjeet
             Raunak
             Samar
    Emma
             Piyush
             Ramesh
             Somesh
    Hendi
             Ratna
             Satna
    Kistrien
             Rachna
             Samrachna
    Maria
             Rolly
             Sameer
    Michael
             Ratnam
             Satnam
    Mike
             Radha
             Sadhna
    Nikki
             Ram
             Shyam
    Nina
             Rita
             Sita
    Robert
             Raman
             Samar
    39 rows selected.

  • Need info on Standard Web services to pull Order data in CRM from external applications

    Hi Gurus,
    I have a requirement to pull Order data in CRM from external non-sap application using Web services. Are there any standard SAP provided web services to pull order data based on some input? If yes, can you provide me any kind of documentation related to this?
    Appreciate your help on this.
    Thanks
    Lakshman

    Hi Lakshman,
    I have checked further.
    Please review below link of the SAP Help documentation :
    http://help.sap.com/saphelp_nw70/helpdata/en/47/3a989cbcef2f35e10000000a1553f6/content.htm?frameset=/en/46/97218e79f115eae10000000a114a6b/frameset.htm&current_toc=/en/d1/802cfc454211d189710000e8322d00/plain.htm&node_id=439&show_children=false
    and also the link :
    –http://esworkplace.sap.com/socoview(bD1lbiZjPTAwMSZkPW1pbg==)/render.asp?packageid=DE0426DD9B0249F19515001A64D3F462&id=347DD31EB5AB4BC592BD8B29C0981A1B
    Hoping that this will be helpful.
    Best regards - Christophe

  • Problem with order data

    Hi, I have a problem with order data. A string column has these values:
    A....
    B....
    PSTA-FRA
    PSTA+FRA
    Q....
    R....
    If i order data directly from db ( select column1 from table order by column1 ) , i obtain this result:
    PSTA-FRA
    PSTA+FRA
    If i create a simple report on that table and order on that column the result is:
    PSTA+FRA
    PSTA-FRA
    I can obtain correct output if I set parameter 'Perform group on server' but if i write a selection formula :
    {table.column} >= 'PSTA+FRA'
    record containing PSTA-FRA value not appear.
    I've tried both with Crytal 8.5 and Crystal 11 R2 sp6, database is Sybase SQL Anywhere odbc connection.
    Thanks in advance

    Ordering is done according to the ASCII values of the characters.
    In R2 create a new report and log onto your DB and select Command for your data source. Paste in the SQL you use to get the data in the order the server users. Then you don't have to use CR to do the sorting. DB Servers are much more efficient at collecting the data than CR is.
    Thank you
    Don

  • I want to pick up Schedule line Delivery date based on Sales Order of Mater

    Hi Experts,
    I have one scenario like,
    I want to pick up Schedule line Delivery date based on Sales Order of Material.
    For example :
    Go to va03
    Give the order no
    Press the enter
    Double click on material.
    Go to Schedule line Tab
    Then we can find out the Delivery date .
    I want to pick up the that Delivery date. Could you please help on that.
    Thanks,
    Amjad.

    Hi,
    schedule line dates are available in VBEP.
    VBEP-VBELN = sales order number.
    VBEP-EDATU = schedule line date.
    REgards,
    Raghavendra

  • Purchase order Delivery date based on PO doc no and PO item no

    hi all
    we have a  requirement to bring Purchase order delivery date in to our report .
    it is in EKET Table - field EINDT.
    Is it possible to get this PO Delivery date in to our data source 2lis_02_itm which has PO Doc no(EBELN) and PO item.no (EBELP).
    In EKET Table the primary key is based on 3 fields. PO Doc no(EBELN), PO Itm.no(EBLEP) and delivery schedule line counter (ETENR).
    In EKET Table the data is like
    PO.NO/PO itm no/ schline counter/delivery date
    1000/10/1/1-1-2011
    1000/10/2/5-1-2011
    1000/20/1/2-2-2011
    1000/20/2/2-2-2011
    1000/20/3/5-2-2011
    so on...
    IF i enhance my datasource and populate the delivery date based on EBELN and EBELP we get only 1 delivery date for all the different schedule lines which is wrong.
    I know there is a separate datasource for schedule line data for purchasing BUT IS IT POSSIBLE TO GET the delivery date based on the different schedules by using some ABAP CODE, SINCE in our datasource 2lis_02_itm we dont have ETENR( SCHEDULE LINE COUNTER FIELD).
    if we use the standard data source  (2lis_02_SCL )it is not fair to pull all that data since we only need 1 field from it.
    Please suggest
    Thanks & Regards.
    Krishna

    Hi Krishna,
    Even though you plan to write some ABAP code or do any processing for a combination of PO document no. and Item no. you will always get multiple records with different schedule line items and it is really impossible to take the delivery date without knowing schedule line item no.
    And even when you said PO delivery date, it is actually means delivery date of any of the schedule line only. If you want to write some ABAP logic then you will have to decide like whether you want to display the First line item date or the last line item date etc. But which is again not a good idea.
    I think you can go for schedule line extractor.
    Regards,
    Durgesh.

  • How to get invoice price based on order date or delivery date?

    Hi,
    Our system is configured to create invoices with pricing based on date of delivery.
    But we have a number of customers who get pricing based on date of order.
    Right now, people are manually changing the price and then generating the invoice.
    Is it possible to:
    1) add a ZZ field in the customer master that indicates which pricing date to use?
    2) have SAP generate the invoice with the correct pricing date based on this selection?
    Thx.
    Andy Jacobs

    Hi Andrew,
    We do have the exact same problem.
    One solution would be to create a new order type. Within that new type you can specify what date should be proposed as pricing date by SAP.
    Unfourtantely, here we are not able to add a new type. Does anyone know how this can be solved in another way?
    Thanks,
    Tim

  • When I import a text file(comma separated )into a numbers spread sheet all the data goes into one column. Why does the text not go into separate columns based on the commas.

    When I import a text file(comma separated) into a numbers spreadsheet all the data goes into one column instead of individual columns based on the comma separators.  Excel allows you to do this during the import..  Is there a way to accomplish this in numbers without opening it in Excel and the importing into Numbers.

    Your user info says iPad. This is the OS X Numbers forum. Assuming you are using OS X… Be sure the file is named with a .csv suffix.
    (I don't have an iPad, so I don't know the iOS answer.)

  • Back order rescheduling based on the order date

    Hi,
    Presently, the back order scheduling is based on the order numbers (A-Z) TO customers.
    We want it to be by Order date sequence oldest to newest.
    How can I achieve this?
    Regards,
    SS

    In the selection screen of V_V2, you can see what you can sort the orders by;
    - Date of creation
    - Delivery date of earliest schedule line
    If this is the date you want, you can choose these as the number 1 priority.

Maybe you are looking for

  • Displaying the contents of JCombo in JTable

    <Re-post from 'New To Java' forum> Hi, I have created a JTable which loads a list of Strings into one of its fields as a JComboBox. The JComboBox defaults to one of the items in the list of String when the frame is loaded. Problems: 1. When the frame

  • Display Conditions for Configurator OptionFeature Options - R12.1

    Here is a test scenario that I am using. This is for R12.1 1. I have a list of options under a Option feature 2. These options are to be displayed as drop down list in the configurator user interface as the min and max selections allowed is 1. i.e. o

  • File open issue, after file deleted. fopen status is failing in VC++

    /* fopen example */ #include <stdio.h> int _tmain(int argc, _TCHAR* argv[])   FILE * pFile;   for(int i=0; i < 1000000; i++)             bool ret = remove("C:\\abc.txt");             pFile = fopen ("C:\\abc.txt","w");             if (pFile!=NULL)    

  • Security Problem while porting to 7.0

    Hi, We are running on 5.1, jdk1.2.2_07, sp12 and tried porting 7.0. We found the following problem below after converting the weblogic.properties file to config.xml. Starting WebLogic Server... <Jul 19, 2002 7:11:14 PM PDT> <Notice> <Management> <140

  • Ipad will not synch or restore!

    Since updating my Ipad iPad (iOS 6) I cant sync or even restore my ipad. This is the worst iOS update I have ever put on my phone or ipad. I am encountering a whole host of other problems. Can someone help me as I cannot even see a feasible way I can