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.

Similar Messages

  • 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 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 order / group a report by a placeholder column ?

    How to order / group a report by a placeholder column populated by the group filter ?
    In more detail .....
    My Data model editor's select statement brings back (say 1000 rows) from the database.
    The group filter decides (on performing certain validations) whether to print a row or not in the report.
    Additionally the group filter calculates a "rule type" (just a rule number to say on basis of what rule, the row was selected)
    I would like to order/group the report on the placeholder column which was calculated by the group filter ?
    Obviously, I won't be able to add the "ORDER BY :CP_RULE_NUMBER" in the sql statement as the placeholer column cp_rule_number
    is determined by the group filter level only. (If I do, I get a frequency error)
    Any ideas ?
    Thanks in advance.
    Edited by: user553361 on 8/10/2008 17:35

    how is the group filter implemented?
    If its pure PL/SQL, what about putting the filter-procedure in a stored function into the database? Then you could use the group filter in your query.

  • 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.)

  • 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.

  • Formating the Row Based on one column value

    Hi Friends
    I am trying to format the Entire row based on the value of the first column in my Answers.
    Example if first column value in 'F' now i want the Entire row to be colored
    I can do conditional formating on one column but i want to do it on the entire row
    F     8.1 %     12.0 %
    E     5.2 %     3.5 %
    M     2.3 %     3.3 %
    If any one has done this or any suggestions please respond
    Thanks
    Sang

    Its a Pivot View
    F 8.1 % 12.0 %
    E 5.2 % 3.5 %
    M 2.3 % 3.3 %
    the column 1 --> F,E,M are the Product
    the column 2 --> 8.1% , 5.2% , 2.3% are the sales in year 2008
    the column 3 --> 12.0 % , 3.5 %, 3.3 % are the sales in year 2009
    So will i be able to apply the formating in pivot view based on one column to other column If yes please let me know how or
    suggest if this can be done using the BI Office , or BI publisher
    sing the BI Office i can do the formating in Excel but once i refresh the data all the formating is gone ... :(
    I am donno BI Publisher if we have to use BIP please suggest any solution its very very very urgent and important report formating they need here ....
    Thanks in advance David
    sango

  • Grouping of data based on user prompt having a list of dimensions

    Hi All,
    I have a requirement to be able to group data in OBIEE request or Dashboard based on user prompt selection.
    The prompt should list the Dimensions Available
    e.g.
    Dimensions: Product, Region, Employee
    Fact: Sales
    The report is to display sales total for the quarters of the current year.
    The user prompt should list the available dimensions (In this case - Location, Employee and Product).
    If I choose Product, the data is to be grouped by Products - Layout having a simple tabular grouping with Product names as Group headings.
    Similarly any other choice of Dimension from the prompt should group the data by that dimension and have the dimension values used in the group headings.
    How could we implement this? I understand this type of requirement (ability to choose dimension) is met in some OLAP reporting tools.
    I have used multiple views and the View Selector for similar requirements previously, but looking for a dynamic solution here.
    Any pointers or solution will be great.
    Thanks,
    Kiran
    Edited by: Kiran Kudumbur on Sep 8, 2009 5:43 PM
    Edited by: Kiran Kudumbur on Sep 9, 2009 12:42 PM
    Edited by: Kiran Kudumbur on Sep 10, 2009 2:26 PM

    Hi All,
    I used column view to address this requirement.
    Thanks,
    Kiran

  • How to achieve same start date for two ATO Items- req to built together

    We have two ATO Items and these to be built & shipped together which have different leadtimes, How we can have achieve same start date when we release from ASCP.
    E.g: ATO_Model1*24234 SO Line 1, the rolled up LT=10Days
    ATO_Model2*325325, the rolled up LT=3
    So, under normal scenario ASCP will suggest two different release dates based on LT. So, I would like to start both Job togther considering the max leadtime.
    Hoping for your expert advice.
    Thanks

    Hi,
    Please check Vendor Master data: FK02 ->company code data -> Payment transaction accounting: unflag 'individual payment'.
    Make a test and let me know if it's okay.
    regards

  • How to calculate Goods issue date based on the time of delivery

    Hi SAP Gurus,
    I seek your help/suggestion for the given scenario.
    The user requires calculating the GI date based on time of delivery.
    Based on the delivery priority (like Priority 1= Day 1, Priority 2= Day 2) maintained in customer master, the need is something like below-
    1st case= If Retail Customeru2019s delivery orders received before midday (Noon cut off) require to be dispatched on same working day (Day 1)
    Wholesaler customer delivery orders received before midday require to be dispatched by the next
    Working day (Day 2 Including day of receipt)
    2nd case= Retail customeru2019s delivery orders received after midday require to be dispatched by the next working day
    Wholesaler customer delivery orders received after midday require to be dispatched by on day 3
    Kindly suggest , how to proceed in this. I am new to SAP world so need ur help to tackle this.
    Thanks a lot in advance for the valuable inputs.

    What I proposed to do was,
    a. Create routes like 0 day route, 1 Day route, 2 day route etc.
    b. Route determination is based on the Shipping condition of the customer. Put in the shipping condition for the customer as 00 - immediate delivery. 01 - By Truck, 02 - By Rail, 03 - Ship etc
    c. Now, put in your route determination in such a way that routes change in the sales order with shipping condition (SC). Like, if the shipping condition is set to 00, then 0 day route comes up. Meaning immediate delivery, if SC is 01, then your normal route by truck picks up. etc.
    When the sales order is manually created, you know the time of creation. As route is one of the criteria, the material confirmation happens based on number of days you put in the route to reach the destination. Now that you have the material available for today's delivery, the delivery program can be run to create it, or it can be manually created.
    Now, when you configure the route you have to specify 'Transit duration in calendar days'.
    When you have the sales order created electronically (say thru EDI), then, you may have to ask them to send in shipping condition. Else, you have to modify the function module Idoc_input_orders in such a way that if the sales order creation time is < 12 PM, then put shipping condition as 00, else copy what ever is there in the customer.
    If you do not want to check the time manually when the user creates the sales order, then you may have to use the user exit MV45AFZZ (and I think you can use Save_order_prepare) to check the time and change the shipping condition. By this you will avoid extra coding in Idoc_input_orders and also need not bother if the user changed the route or not.
    Hope my explanation helps.
    Regards,
    Mukund S

  • How to consolidate rows of data based on a single column?

    I have a large amount of data that is currently formatted like this:
    18 - 2 - 0 - 0 - 0 - 0 - 0 - 0 - 0
    18 - 0 - 4 - 0 - 0 - 0 - 0 - 0 - 0
    18 - 0 - 0 - 5 - 0 - 0 - 0 - 0 - 0
    19 - 0 - 2 - 0 - 0 - 0 - 0 - 0 - 0
    19 - 0 - 0 - 0 - 5 - 0 - 0 - 0 - 0
    20 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0
    20 - 0 - 0 - 0 - 0 - 0 - 3 - 0 - 0
    20 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 2
    I would like to sort it all based on the value in first column. Currently, each row has only 2 (non-zero)
    values. The first in column A, and another in only ONE of the other columns. I want to consolidate the rows according to the value in column A. The final product should look like this:
    18 - 2 - 4 - 5 - 0 - 0 - 0 - 0 - 0
    19 - 0 - 2 - 0 - 5 - 0 - 0 - 0 - 0
    20 - 1 - 0 - 0 - 0 - 0 - 3 - 0 - 2
    How can I go about doing this?
    Thanks in advance

    Use advanced data filters to create a unique list based on column A in another range, then use SUMIF formulas keyed to those values to sum the other columns.
    Or use a pivot table, with column A as the row field, and the others as data , each set to sum. and then drag the data button to the column field area.

  • How to avoid grouping by date with dates as incoming parameters?

    Hello, I have the following Query from SAP Business One set as DataSource:
    SELECT  T1.SlpName as 'Vendor', convert(varchar(12), T0.[U_ER_PROV])as 'City', T0.[CardCode] as 'Client Code', T3.CardName as 'Client Name', T0.DocDate as 'Date', T2.ItemCode, T4.ItemName as 'Reference Description', sum (T2.Quantity) as 'Toal Units per Reference',
    avg (T2.Price)as 'Average Price', sum(T2.LineTotal) as 'Total'
    FROM ODLN T0
    INNER JOIN OSLP T1
    ON T0.SlpCode = T1.SlpCode
    INNER JOIN DLN1 T2
    ON T0.DocEntry = T2.DocEntry
    INNER JOIN OCRD T3
    ON T0.CardCode = T3.CardCode
    INNER JOIN OITM T4
    ON T2.ItemCode = T4.ItemCode
    group by  T1.SlpName, convert(varchar(12), T0.[U_ER_PROV]), T0.[CardCode], T4.ItemName, T0.DocDate, T2.ItemCode, T3.CardName
    order by  T1.SlpName, convert(varchar(12), T0.[U_ER_PROV]), T0.CardCode, T0.DocDate, T2.ItemCode
    What I´d like to do is, grouping in Crystal Reports, the result of this query by Item Code, not by date. The problem I have is that I need users introduce "from date" to "end date" as incoming paramater.
    The way I am running it, for example  I have some results like:
    date                         Item Code               Total
    01/01/2009               4646_R2                  120 u20AC
    10/01/2009               4646_R2                  34 u20AC
    And I´d like to take something like this:
    Item code                       Total
    4646_R2                         154 u20AC
    Not grouping by date ......
    Is there any way to do this using this query in Crystal Reports?
    Thanks very much for your time.
    Miguel A. Velasco

    Hello all, thanks very much to  Raghavendra for his helpfully answer.
    I followed your coments and now the report is running fine.
    Thanks again for your help without expecting anything in return.
    Miguel Velasco

  • How to achieve the sorted data from BEx report.

    Hi Guys.
    I have a report which is having characteristics called customer and posting date.
    when i execute that report i want data in assending order of  first customer and next posting date.
    I have given customer as sorting character in BEx display tab of customer  and then i have given Posting Date also in display tab of posting date. But when query is executed its showing as execel will sort.
    for ex.
    C001          5/29/2007
    C001          6/1/2007
    C001          6/3/2007
    C001          6/3/2007
    C001          10/1/2007
    C001          10/4/2007
    this is how i want see my data
    but i am seeing as below
    C001          10/1/2007
    C001          10/4/2007
    C001          5/29/2007
    C001          6/1/2007
    C001          6/3/2007
    C001          6/3/2007
    Kindly anyone help me out.
    thanks
    peter

    Hi,
    I hope , you can set the property of Posting date by right click on it in the query designer, to make the report display on the required Sorting order.
    With rgds,
    Anil Kumar Sharma .P

  • How to use multiple Spry Data Sets in one page

    I'm using two spry data sets in one page. When I add the first spry data set to my page everything runs OK, When I add the second spry data set to the page the first data set stops working. Does anyone know what the problem is?
    This is how I have my data sets listed.
    var ds1 = new Spry.Data.HTMLDataSet("/accounts/tower/list.php", "list");
    var ds2 = new Spry.Data.HTMLDataSet("/accounts/tower/numvisits.php", "chart");
    Thanks, let me know if you need more information.

    Good News!
    There is nothing wrong with what you have shown.
    Bad news!
    The problem could be in that part that you have not shown.
    Gramps

Maybe you are looking for