Grouping and subgrouping

Hi Experts,
I am looking for select which can give me results as below. I am fairly new and tried
Data
=====
select 'g1' group_key,'p1' prod,'pd1' prod_dsc,'m1' month ,1 sales from dual
union all
select 'g1','p2','pd2','m1',2 from dual
union all
select 'g1','p3','pd3','m2',3 from dual
union all
select 'g2','p4','pd4','m1',4 from dual
union all
select 'g2','p5','pd5','m2',5 from dual
union all
select 'g3','p6','pd6','m2',6 from dual
ouput
=====
g1
p3
pd3
m2
6
p3
pd3
m2
3
p2
pd2
m1
2
p1
pd1
m1
1
g2
p5
pd5
m2
9
g2
p5
pd5
m2
5
p4
pd4
m1
4
g3
p6
pd6
m2
6
g3
p6
pd6
m2
6
So basically prod,prod dsc and month is not known for the group but it will be taken from the highest sales within the group. Any help is highly appreciated.
Thanks,

with order by :
WITH T AS(
select 'g1' group_key,'p1' prod,'pd1' prod_dsc,'m1' month ,1 sales from dual
union all
select 'g1','p2','pd2','m1',2 from dual
union all
select 'g1','p3','pd3','m2',3 from dual
union all
select 'g3','p6','pd6','m2',6 from dual
union all
select 'g2','p4','pd4','m1',4 from dual
union all
select 'g2','p5','pd5','m2',5 from dual
select decode(grp_id,0,null,group_key) group_key,
       prod,
       prod_dsc,
       mnth,
       sm_sales,
       row_number() over (partition by group_key order by decode(grp_id,0,null,group_key)) o
from(
SELECT t.group_key,
       max(t.prod) keep (dense_rank first order by t.sales desc) prod,
       max(t.prod_dsc) keep (dense_rank first order by t.sales desc) prod_dsc,
       max(t.month) keep (dense_rank first order by t.sales desc) mnth,
       sum(t.sales) sm_sales,
       GROUPING(t.group_key) grp,
       GROUPING_ID (t.group_key,t.prod) grp_id
FROM T
group by rollup(t.group_key,t.prod)
where grp = 0
GROUP_KEY
PROD
PROD_DSC
MNTH
SM_SALES
O
g1
p3
pd3
m2
6
1
p1
pd1
m1
1
2
p2
pd2
m1
2
3
p3
pd3
m2
3
4
g2
p5
pd5
m2
9
1
p5
pd5
m2
5
2
p4
pd4
m1
4
3
g3
p6
pd6
m2
6
1
p6
pd6
m2
6
2
Ramin Hashimzade

Similar Messages

  • Pharma specific fields (group and subgroup)

    Hallo,
    I have problems with specific Pharma fields (group and subgroup) in CRM Mobile 2007 SP02.
    Some business partners have group and subgroup in pharmaceuticals bookmark in transaction BP.  But in mobile solution I have these business partners without group and subgroup. The combobox for group and subgroup is empty too.
    In table SMOKNA1 (in CRM server and in CRM mobile are columns KVCGROUP and KVCSGROUP empty). I tried make initial load for object CRM_DNL_BPGROUP, but all is the same.
    Have anyone suggestion what I made wrong? Which subscription I need for these attributes.
    Thank you for your help.
    With regards,
    Jiri Halmich

    Hi,
    the issue with the customizing data is solved as Jiri already mentioned above.
    Btw: After synchronizing an adapter object you don't need to run an extract as this is done automatically by the system - and only for the changes (delta sync), not for the complete subscription...
    Concerning the missing data in smokna1: For my understanding this is a standard error. You should create an OSS message for that.
    If you prefer to solve it at your own you would have to do some coding in the Mobile bridge. Using the EEWB dosn't help as the fields are already there in the tables and BDocs.
    Of course you also can chose a "quick & dirty" solution: Create a new CDB table, containing only the sfakna1 and the both BP group fields, define an adapter object which synchronizes the both fields from BUT000 to this table and calculates the sfakna1 field by keygen. Run this adapter object by using a batch job at least once a day. Create a new sBDoc and qBDoc based on this table. Do some small coding in BOL to retrieve the both properties from the new CDB table into the both BOCAPGEN properties.
    Regards,
    Wolfhard

  • Creating Employee Group and subgroup in OM

    Dear Viewers,
    I am new in this SAP, I have started learning SAP HR / HCM. Presently I am learning OM and creating Organisational Structure.
    Can anyone help me in giving examples to create employee group and employee subgroup categories.
    Thanks & Regards,
    Soujanyah

    HI Swapnil,
    Thank you for the link.
    I have got a sample by searching in google
    [http://www.laccd.edu/hr/Documents/HRGuide_H-300_EmployeeSub-Group.pdf]
    Can I get some other samples please as specified in that table as EG and ESG

  • Propose or change automatically, Employee Group and Subgroup.

    Dear all, when executing an exit Action, thru transaction PA40, what's the best way to propose by default/change automatically, the employee group/subgroup?
    Example: I want to change the employee group from '1' (Active) to '2' (Inactive), but the fields are disabled for input.
    Do i have to do this thru the enhancement "PBAS001", or is there any way to do this thru configuration?
    Sincerely,
    Hugo Ferreira

    I was searching for something in SDN and got this post.
    Though it's a very late reply, whatever Sreenu has told is correct.
    In the table T529A, you can define the employment status wehther it has to be active, withdrawn or inactive.
    This field is input disabled in the action and the values will be defaulted from the configuration.
    But Changing the employee group and employee subgroup , we can't change. If that is what is required, the values might depend on the configuration.
    And even through some enhancement also we can't change. because, for IT0000 no enhancement are available. Even though the fields are from IT0001, I doubt it can be changed through enhancemnet.
    If you have already achieved it through enhancemnet, please let us know.
    Thanks,
    RSS.

  • Problem with Group and SubGroup

    Hi All,
    I have one problem in sql statement. I got two tables, PARTY and SUBGROUP.
    <<party>>
    party     group     subgroup;
    WG009     xx     zzz
    <<subgroup>>
    party     group     subgroup;
    WG009     xx     yy
    I have to write a query which gives the result that 'zzz' is not in subgroup table where xx=xx from subgroup.group and party.group. I have written the statement like this, but its not working properly becuase its returning all the records from subgroup.
    SELECT P_CODE, SG_CAT, P_CAT, P_SUB_CAT, SG_CODE FROM PARTY, SUB_GROUP WHERE P_CAT=SG_CAT AND SG_CODE != P_SUB_CAT AND P_CODE='WG009';
    P_CODE SG_CAT P_CAT P_SUB_CAT SG_CODE
    WG009 DWD DWD ANIL SHAH GADAGE
    WG009 DWD DWD ANIL SHAH JAIN FAMILY
    WG009 DWD DWD ANIL SHAH DEDHIA
    Is any body have Idea.
    SKM

    select party,group,subgroup from party
    minus
    select party,group,subgroup from subgroup;

  • Item grouping into groups and subgroups

    In case there are a lot of items in Business One, companies usually group these by item groups. In some cases when there are thousands of items, these are further on divided into subgroups by using UDFs. Then when you are making, say a sales order, you first look for the item group and then for the subgroup. This is where it gets tricky. You can only display the code when browsing for subgroups. It is not possible to display the value within the description field (I do not know how to do it). The code lenght is limited to 8 characters and hence makes it difficult to write a proper description for this subgroup. Is there any way to overcome this issue?

    Hello,
    thank you Gordon and Deepak for your efforts. First level grouping (B1 standard) by item groups is working fine, the second level just displays codes. The issue is that the value within udf-field on item master data card (on the right-hand side) does display correctly. However when I search for this item, say when making a sales order, I will just get the value, not the description. It makes no difference if I select it in the document settings to display as visible.
    Codes and description for this udf-field are as follows:
    Code  Description
    100    Roses
    110    Tulips
    120    Lilies
    Now when I sort this field by subgroup value, it only displays 100, 110 etc.
    All help is appreciated.
    Thanks,
    Samuli Ajo

  • Need scripts for fetching groups and subgroups info , script for del users

    Hi ,
    I need a script or macro which will fetch list of groups and sub groups triend forums download did not fine one.
    I need another script which will delete listed users there is a macro in forums but it doesn't suit my rquirement.
    Any one have these scripts handy with you please help me with that,
    Regards,
    Neo.

    Hi Braham,
    Thanks for your quick reply.
    Are we able to do this on two stage method
    1. grab the security groups from the share paths
    if can grab the share path from a separate txt file than copying it to the <your path> location
    so i can modify the txt file
    once run the script
    if can the output like below to a CSV file
    \\servername\foldermain\folder1group 1group 2group 3\\servername\foldermain\folder2group 1group 2group 3then i know which groups belongs to which share paththen i can remove the duplicate groups and keep the common groups to grab the users belongs to itso with the second script same as the first copy the security groups to a txt file and the out put as below.what I needs is the users full name and the samaccount name ( user id )group 1user1user2user3
    group 2user1user2user3looking forward your help on thisThank you.Thilo

  • Issue in uploading Employee Group and subgroup in LSMW

    Hi Experts,
       I`m using LSMW to upload IT 1013 data thru transaction PP01. When i run the LSMW in forground mode , then everything seems to work fine. But when run in background mode, I find that the records are not getting uploaded and its giving me some error like "Runtime error RAISE_EXCEPTION has occurred".
    Any input regarding this would be helpful and appreciateable.
    Regards,
    Farhana

    Hi Anatha,
        I tried PP02 and it also shows me the same error and also the my data files has only 4 records. I`m using only 4 records for testing, so it could not be a mass data load issue too.
    Regards,
    Farhana.

  • Change employee group and sub group

    Hi all,
    During the new hire if an employees group and subgroup are enetered wrongly, how shouldl they be corrected. We have scenarios when the emplooyes group and sub group are corrected after a month or so and the users want to correct the same
    How do we do it?

    Goto PA40 reselect the same Hire action for this employee and click execute. In IT0000 screen enter the new EG/ESG.
    and save it. Then Save the IT0001, then fill rest of the infotypes.
    If you have already process the payroll and the new Emp group / Sub group is in different payroll area you wont be able to change it.

  • Employee group and Employee Subgroup....

    Hi Experts,
    I am just learning SAP now..... 
    I had created employee group(1 Employee) and employee subgroup(3Y executive), and i assigned employee group to subgroup, and i checked in the table T503Z,, even though it is showing an error while creating relationship.... the error is "entry 1 3Y doesnot exist in T503 check your entry" .
    please reply me with IMG Path(SPRO)
    regards
    gosammy

    spro>Personnel Management>Personnel Administration>Organizational Data>Organizational Assignment-->Define employee attributes(V_503_C)
    I think u missed this table , here u have Activity Status, Employment status, Training Status.Keep the cursor in the relevant feilds and go for f1(help) and  fill the data
    Best Regards,

  • Error Message Employee Group must be 9 and Subgroup can only be- Terminatio

    Hi Gurus,
    I am trying to execute the Action Termination with action reason 71- Retiree normal.  In the Actions infotype IT0000.  I am getting the below error.  I have checked all the configuration checked T529A, T503*, T528B etc...  All are maintained correctly.  When trying to execute with other action reason it is getting saved.
    Employee Group must be 9 and Subgroup can only be
        Message no. Z7016
    Appreciate help from any of the SAP Gurus.
    Thanks
    Naveen Avalur

    Hi Donnie,
    Thanks for your quick turnaround.  The answer was very helpful.  We are working along with our programmers.
    Will let you know if the solution is found.
    Thanks
    Naveen Avalur

  • Creation of new employee groups and sub groups

    Hi All,
    What all the steps should I follow to create new employee groups and sub groups? and  How many structures should I create for this?
    Its urgent pls.......
    Good replies will be rewarded!!!!
    Regards,
    Sita

    Hi
    You can create the employee groups depending up on your clients requirement, Eg: Permanent, Temporary, Seasonal, Trainee, Advisor etc
    And define the employee subgroups and assign them to the employee groups Like
    Enterprise structure>Definition>Human Resource Management-->Employee Groups & Employee Groups
    Enterprise structure>Assignment>Human Resource Management-->Assign employee subgroup to employee group
    you can create employee subgroups depending up on your requirement like asst manager, manager, GM, MD, VP ETC an assign them to the employee subgroups ok.
    Ensure that certain empployee subgroups may not be assigned to employee group based on requiremen, but create all the employee sub groups which is existing in the organization.
    Regards

  • Order between elements and subgroups

    Hi all,
    I'm building a Data Template to generate just an XML output (without using any RTF template) and I have a problem with the order among the elements and subgroups, both defined in a main group.
    This is my Data Template:
    <group name="FileHeader" source="Q1">
                        <group name="TotalExecutableAmount" source="Q1">
                             <element name="TotalAmount" value="AMOUNT_REM"/>
                        </group>
                        <element name="InvoiceCurrencyCode" value="CURRENCY_CODE"/>
    </group>
    and my final output:
    <FileHeader>
    <InvoiceCurrencyCode>EUR</InvoiceCurrencyCode>
    <TotalExecutableAmount>
    <TotalAmount>0</TotalAmount>
    </TotalExecutableAmount>
    </FileHeader>
    As you can see, it places the "InvoiceCurrencyCode" field before the subgroup "TotalExecutableAmount" although the subgroup is first in the Data Template.
    ¿Do you know any tag or property to force the Data Template to respect the original order?
    ¿Any other suggest?
    Thanks in advance,
    Carlos Herrero García

    Thanks Rainer. It's important because I need to validate the invoice's xml-structure against a Spanish Government system that fixes this order. Anyway, I agree you that it shouldn't have any importance.
    Carlos.

  • ICR 002 - Object Groups and Sets

    Hi,
    Tcode here is FBCR009.
    I need one help on the PROCESS 002 for ICR. In the current system, we have implemented the Object groups and Sub groups as mentioned below:
    Object Group - 100
    Object Subgroup 100
    Object group  Sequence      Company Field  Company Set   Description                   Partner Field     Partner Set    description
    100     1     RACCT     RULE2A     B/S Cash Management     RACCT     RULE2B     B/S Cash Management
    100     2     RACCT     RULE3A     B/S ST Interest Bearing     RACCT     RULE3B     B/S ST Interest Bearing
    100     3     RACCT     RULE4A     B/S ST Non-Interest Bearing     RACCT     RULE4B     B/S ST Non-Interest Bearing
    100     4     RACCT     RULE5A     B/S ST Non-Interest Bearing Derivatives     RACCT     RULE5B     B/S ST Non-Interest Bearing Derivatives
    100     6     RACCT     RULE7A     P&L LT Interest     RACCT     RULE7B     P&L LT Interest
    100     7     RACCT     RULE8A     P&L ST Interest     RACCT     RULE8B     P&L ST Interest
    100     8     RACCT     RULE9A     P&L Toll     RACCT     RULE9B     P&L Toll
    100     9     RACCT     RULE10A     P&L Royalties     RACCT     RULE10B     P&L Royalties
    100     10     RACCT     RULE11A     P&L Rent     RACCT     RULE11B     P&L Rent
    100     11     RACCT     RULE12A     P&L Brokerage Commission     RACCT     RULE12B     P&L Brokerage Commission
    100     12     RACCT     RULE13A     P&L Warehousing     RACCT     RULE13B     P&L Warehousing
    100     13     RACCT     RULE14A     P&L Misc/Other     RACCT     RULE14B     P&L Misc/Other
    100     14     RACCT     RULE15A     P&L Insurance     RACCT     RULE15B     P&L Insurance
    100     15     RACCT     RULE16A     B/S LT     RACCT     RULE16B     B/S LT
    I am a little confused here. The following sets under the sub-group has a logical u201CANDu201D . the customer corporate reporting group would like to see the Config to allow each group of accounts defined as ruleXa reconciled to group of accts defined as ruleXb, e.g.
    Rule 2A with Rule 2B
    Rule 3A with Rule 3B etc
    Each Company set should only reconcile with the partner set.
    looked at this OSS Note 1499183 - ICR: Documents are not assigned to the object groups & got even more confused.
    Request if you can advice here.
    Regarzds
    Aahish

    Hello Johannes,
    Unfortunately what you are trying to do is not possible.
    Object groups are defined using the information in the totals table. Therefore fields only available in the line item table cannot be used when setting up object groups. Unfortunately it is also not possible to set up status fields on the totals level because of the standard update process of those fields when setting a status (the line item table is modified directly, there is no totals update). Depending on the details of your setup you might be able to simply add a "normal" field on the totals level and then fill it via BADI. This would probably work quite well if the field does not have to be set manually - and in this case you do not really need the functionality of setting a status manually either.
    I hope this helps you in your efforts!
    Ralph

  • Groups and Auxs - confused Newbie

    Can someone please explain the difference between a group and a bus.
    Case: I want to group my drum tracks to a group to apply automation etc. If I create the group in the mixer, select each drum track and say t's art of the groupdo I still need to apply a 'send' in each track inspector to the aux/bus of the same number as teh group?
    I'm sure this is a Doh! moment for many but despite reading three manuals I can't understand the logic (no pun).
    Thanks

    Older versions of Logic (up to 7?) had "Bus Channels" - if you have an older project or template, you will have these objects. If you are in version 8 or 9, creating a new file from scratch which will not have these objects.
    An auxiliary is a CHANNEL and a bus is a PATH.
    This is the way it should have been implemented from the beginning, but it wasn't so the confusion spread. A bus is any circuit accepts input from multiple sources. Other than the channels, most everything on an analog mixer is a bus; the main stereo mix, the submasters, the auxes, the matrix, etc.
    Think of a bus as a virtual wire. It can be tapped into for a variety of things, from aux sources to compressor side chains. Once you put a signal on a bus in Logic (usually through an aux send) that signal can be used in multiple ways, by multiple objects.
    The auxiliaries can be used for effects or for subgrouping. They are channels with faders and inserts. On hardware mixers, the auxiliary 'channels' are usually little more than level knobs for input and output. Obviously, larger consoles have much greater flexibility in this regard.
    In Logic 8 and 9, you can create a bus "object" in the environment. I wouldn't touch this, BUT IF YOU DO, the cool thing is that you can get at the signal on the bus and effect it - if you want to.
    For example, say you had a snare on track 1, and used an aux send (at unity) which sent its signal over bus 1 to auxiliary 1. If you created a 'bus object' in the environment and pulled down the faer by -6dB, the auxiliary will get a signal that is 6dB down from unity.
    An auxiliary is a channel, a bus is a path (except for that crazy 'bus object')
    Paul

Maybe you are looking for