Grouping by the results of a group by

I want to group the results of a query that itself is a group by (I have simplified it).
select Id, MAX(type), MIN(type), COUNT(*)
from aa
group by Id
gives
1 03 01 2
2 03 01 2
3 01 01 1
4 03 01 2
5 03 01 3
and so on (there are over 100,000 rows in my actual results)
now I want to group by the Max, Min and Count columns to give (continuing the example):
Max, Min, Count, New Count
01 01 1 1
03 01 2 3
03 01 3 1
I could load the results of the first group by into a temporary table and then do a second (group by) query on the temporary table.
Has anyone got a better way?
Richard Body

SELECT max_type,
       min_type,
       count_id,
       COUNT(*)
FROM
  select Id, MAX(type) max_type,
             MIN(type) min_type,
             COUNT(*)  count_id
  from aa
  group by Id
GROUP BY max_type,
         min_type,
         count_id

Similar Messages

  • Delivery grouping and the delivery date for group in SD

    Hi
    Using a userexit I am grouping certain materials together.  However the delivery date for group field is not picking up the expected date.
    Assume the following example:
    Material X            Delivery Date 20.12.2006
    Material Y           Delivery Date 27.12.2006
    If I group them together I expect the delivery date for the group to become 27.12.2006 however it is picking up 20.12.2006.
    If anyone has some thoughts regarding this they would be most appreciated.

    Yeah got ur point i was mapping the table configuaration for ur reference.
    This grouping is supposed to make sure that all materials are delievered at the same Date (VBEP-EDATU) and must use the last date in the delivery group.
    say materials  X -- DELIVERY DATE  20 12 2006
                         Y -- DELIVERY DATE  27 12 2006
    so the matnrs are avalaible in VBAP along with  for the VBELN and POSNR values now pick the delivery date for this material from VBEP   ,,
    Now once the itab is sorted by delivery group  and EDATU descending .
    so X and Y are present in for delivery group 001 say .
    X -- DELIVERY DATE  20 12 2006
    Y-- DELIVERY DATE  27 12 2006
    after sort by date it will be
    Y-- DELIVERY DATE  27 12 2006
    X -- DELIVERY DATE  20 12 2006
    which will pick up the latest date (or max date)
    Tis was what i meant to say.
    what is the incude you r using ?
    regards,
    vijay

  • Create group in the contact list, create group in the contact list ?

    Create group in the contact list?

    You can create groups by using your mac (granted iCloud is turned on for contacts so it can sink the group to your devices) or by going to iCloud.com. Once you create the goup on the web app it will sync to your devices.
    From icloud.com, select contacts and in the bottom left corner there is a "+" sign, click that then click create new group.

  • How do I create multiple contact groups in the iphone?

    I am syncing w/ Windows Contacts in Vista. Is it possible to create multiple groups of contacts? For example - a group for friends and family, another group for customers, etc...

    Ansuz82 wrote:
    I do it by setting up different categories in Outlook. These sync as groups to the iPhone
    I created groups and organized all my contacts into the groups using Outlook. However, the iPhone doesn't give me the option to view the contacts in groups, nor does it even mention or list the group name when you view the contacts individually.

  • Use the for-each to group the element across in output

    I have the report in XMLP for which we need to design the template to generate the output in excel. we need to group the element across the report. by default the for-each group the element top-down, is there any option to group the elements across. example:
    consider the xml data as
    <?xml version="1.0"?>
    <XXFA_TAL_REP_XMLP>
    <LIST_G_DAY_WE_EXECUTED>
    <G_DAY_WE_EXECUTED>
    <DAY_WE_EXECUTED>18-NOV-09</DAY_WE_EXECUTED>
    </G_DAY_WE_EXECUTED>
    <G_DAY_WE_EXECUTED>
    <DAY_WE_EXECUTED>19-NOV-09</DAY_WE_EXECUTED>
    </G_DAY_WE_EXECUTED>
    </LIST_G_DAY_WE_EXECUTED>
    </XXFA_TAL_REP_XMLP>
    if we group by the above data with group G_DAY_WE_EXECUTED and try to print the data element - DAY_WE_EXECUTED we will get two fields as below
    18-NOV-09 - in excel cell A1
    19-NOV-09 - in excel cell A2
    but we need to have these fields in excel cells - A1 & B1
    Please help me to achieve this.
    ~ Ashish | 630 487 9486

    Can you try with
    for-each@column

  • Cisco Prime 2.1, Removing Subgroup from Group in the Device Work Centre

    Hi All,
    I am having trouble removing a Device Group from within a Group in Cisco Prime.
    In short, there is a group called 'Cisco 3850 Series Ethernet Stackable Switch' which exists under both the 'Wireless Controller' group and the 'Switches and Hubs' group. I want to remove it from the 'Wireless Controllers' group as we are not using the controller functionality of the deivce.
    Can anyone help on this issue?
    Thanks,
    Cameron

    Hi TD,
    I would suggest you to take both the backup ::
    Application and appliance backups
    Prime Infrastructure creates two types of backups:
    Application backups: These contain all Prime Infrastructure application data, but do not include host-specific settings, such as the server hostname and IP address.
    Appliance backups: These contain all application data and host-specific settings, including the hostname, IP address, subnet mask, and default gateway.
    Note that:
    Application and appliance backups can be taken from both virtual and hardware appliances.
    Either type of backup can be restored to the same or a new host, as long as the new host has the same hardware and software configuration as the host from which the backup was taken.
    You can only restore an application or appliance backup to a host running the same version of the Prime Infrastructure server software as the server from which the backup was taken.
    You cannot restore an application backup using the appliance restore command, nor can you restore an appliance backup using the application backup command.
    refer the below links::
    http://www.cisco.com/c/en/us/td/docs/net_mgmt/prime/infrastructure/2-2/administrator/guide/PIAdminBook/backup_restore.html#10347
    http://www.cisco.com/c/en/us/td/docs/net_mgmt/prime/infrastructure/2-2/administrator/guide/PIAdminBook/backup_restore.html#72460
    Thanks-
    Afroz
    ***Ratings Encourages Contributors ****

  • RE: The selectBooleanRadio component's group attribute is null

    Hi all,
    i am using Jdeveloper 11.1.2.3.0
    I have one Read only table in my fragment which contains one Checkbox and one Radio button.
    Here i have one requirement that whenever i check the checkbox the radio button will get enabled.
    I have done all the things regarding my requirements that is whenever i check the checkbox the radio button is enabled with an error message  in log.
    The log message is as follows:
    The selectBooleanRadio component's group attribute is null. It must be set to a non-null value for the selectBooleanRadio component to function properly. The selectBooleanRadio component is meant to be used with other selectBooleanRadio components with the same group value.
    So, Can any one help me to resolve the above issue.
    Regards,
    Syam

    Hi,
    I think an error message cannot be more clear than this;
    The selectBooleanRadio component's group attribute is null. It must be set to a non-null value for the selectBooleanRadio component to function properly.
    selectBooleanRadio component's group attribute  ==> the selectBooleanRadio has a "group" property that you need to define a value for
    Frank

  • AB Smart Group "is not  member of" a group not working

    After having some trouble with AB over time (group members disappearing after some time syncing via MobileMe), I went through the 1700 cards one by one and deleted all the groups, and old cards, now am down to 1500, with a main Group of about 900. So simple math would say that there are 600 "not a member of" the main Group, or, #1, am I missing something there?
    I'd like to have my wife go through those that are not in the Group and delete those cards she doesn't need. So I tried a Smart Group with the one parameter that the Card is not a member of the Group. The result was 64 cards, not 600.
    So question #2 is what's going wrong here, am I misunderstanding or is this a flaw somehow?
    Thanks!

    As far as I know, Apple does not monitor these boards any more. Remind them here:
    http://www.apple.com/feedback/macosx.html
    I just sent them a note, as I'm sure thousands others have since this seems to be a known issue, but considering they've let it slide for at least six months now, it can't hurt to have more people contact them. In the mean time, see these articles to use AppleScript to find items in/not in various groups:
    http://www.macworld.com/article/56952/2007/03/ungrouped.html
    http://discussions.apple.com/thread.jspa?threadID=1704973&tstart=1560

  • Field"Code group" is not in the result for report CRM_SRV_REPORT

    Hi Guys,
    For the tx CRM_SRV_REPORT - Service Process Monitor, the field "Code group" is not in the standar result, but, is in the initial screen for filter selection.
    This field is not available in the layout modification.
    How can I add this field to the layout of the result list?
    Regards,
    Lyda

    Hi Lyda,
    Additional field cannot be added in the layout of the result list.
    If you will observe the code of the report CRM_TSRV_REPORT, in the field catalog, there is not Code, code group etc., hence it is not seen in the layout.
    Since it is a std report it cannot be modified, either u can create a Z report by copying this or u can raise an OSS message for this.
    Regards,
    Shalini Chauhan

  • I've found no way to sort.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results.

    I've found no way to sort search results in itunes.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results. 

    In the Search box click on the black Arrow and UNTICK the Search Entire Library.
    Then the Search results in Songs view will be displayed in the main Grid and you can sort them by clicking on the column headers.
    You can also turn on the column browser which can help with filtering

  • How do I put a label in a null field in the result set of a group-by query

    I run the query:
    select section, count(*) from nparcel group by section
    and get the result
    section1 100
    section2 200
    section3 300
    400
    I would like to modify the query to put a label, perhaps 'BLANK', in the last returned row. Is that possible and if so how.
    Thanks in advance for helping.

    Hi,
    In SQL*Plus you have some additional options, that apply to all queries until you override them or end the session.
    COLUMN section NULL BLANKapplies only to the column called "section".
    SET NULL BLANKApplies to all columns.

  • How to display the results of the grouping horizontally

    Hello,
    I still cannot understand what am I doing wrong when trying to display the results of the grouping horizontally. Here is the original thread: How to group report vertically
    In the Section expert, for Detail section, I check the box Format with Multiple columns. Under the Layout tab, I check Format groups with multiple columns and set the width of the column at 3.3 in. This should give me 3 columns for Landscape orientation.
    Now if I select Printing direction Down then Across, I just have the regular vertical grouping.
    If I check Across then Down, then I do get 3 columns, but all the records in the Detail section are also spread across first instead of staying in the column.
    There should be something else that I should do to get the display like this:
    Header1    Header2    Header3
    record11   record21   record31
    record12   record22   record32
    record13   record23   record33
    etc.            etc.            etc.
    Thank you.

    I'm not at all sure columns are gonna help here, as there is no way that I am aware of to tell Crystal to start a new column.
    The only way that I can think of to achieve what you are trying to accomplish is to do something like this:
    In your group header's Suppress formula, keep track of the first (/ next) three groups that you want to print, using something like (basic syntax):
    global grouplist(3) as string
    global groupcount as number
    groupcount = groupcount + 1
    grouplist(groupcount) = {db.GroupingField}
    ' The NextIsNull below implies End-of-Data...
    if groupcount = 3 or NextIsNull({db.GroupField}) then
      formula = false  ' print the group header
    else
      formula = true  ' suppress the group header
    end if
    Then, create three formula fields to get each value in grouplist().  The group header format will then show the three formula fields.  Underneath these three formula fields, add subreports, which will show the details for one specific group.  The subreports should have a parameter for which group's details to show.  Use the three formula fields as the link to the three subreports.
    In the group footer, clear out the grouplist() array, and set groupcount to zero.
    This report will take a while to run, because having three subreports next to each other makes it difficult for Crystal to determine page formatting.
    HTH,
    Carl

  • Suppress a Group Based on the Results of a Formula

    Hi All,
    Been reading through this forum as I am new to Crystal.  I have a report that must display a group of records along with their detail if  TotQOH > RunningTotal.  I tried using the running totals field in Crystal but I could not reference a formula in the selection criteria since it must be evaluated later.
    Reading up on this forum I figured out how to create my own running totals (also referenced the application's help article ' Creating running totals using a formula') but now I can't seem to suppress the entire group and corresponsing detail records when TotQOH > RunningTotal.    Using the Formatting Formulas in the workshop tree of the Formula Editor, I can suppress any of the fields within the group but this leaves me with a bunch of blank lines in the output.
    I'm using Crystal 10 and simply want to suppress the entire group and the corresponding detail while printing the records when:
    TotQOH > RunningTotal
    I read this thread: Selection Formula based on Running Total, but could not get this to work for the entire group, just the fields within the group.
    Any ideas would be welcome.  Thank you very much.

    I'll have to research subreports - never worked with them.  After I suppressed all the fields, I went to the section expert and checked Suppress Blank Section, ran the report and nothing printed.  There are many records that meet the criteria TotQOH > RunningTotal, so I'm going to do more research and take a look at subreports.

  • How to add a sub report at the end of the main report whilst grouped

    Hi!
    I have a main report that is grouped by the Customers name and then details of transactions they did with the company.
    I need to add a letter at the end of each group for each customer (With their name displayed in the letter). I tried adding a sub report in the report footer, but it only appears once at the end of the report, rather than at the end of each group for each customer.
    How can I achieve the desired result?
    Regards
    Vik

    Vik,
    You are on the right track with the sub-report.
    1. Create your letter in a separate report.
    2. Add the Letter Report to your original report as a sub report in the group footer.
    3. Set the report links on the "Group By" field.
    This will give you a letter record for each report record with the same grouping as the main report.
    Hope this helps,
    Jason

  • Is there a way to change the duration of a group of selected clips all at once?

    Hi all,
    I'm working with good old Premiere 6 on Windows 7.
    Is there a way to change the duration of a group of selected clips all at once?  If I have a large group of clips in my timeline that are all the same duration, once I've selected them all in a group, can I somehow change the frame number duration of all the clips at the same time?
    I've found other things that can be done to a group of clips at the same time, but I can't find a way to change the duration of a group of selected clips.
    Thanks,
    digi

    Thanks Jim and Bill,
    In my efforts to work around the problems with the distortion and horizontal interlace lines that come when using the Motion Settings, I'm doing stop frame animation with hundreds and hundreds of layers in PSDs in multiple files placed in hundreds of one, four and six frame sections in Premiere, so if I find that I need to change the number of frames per clip in hundreds of consecutive clips (not actual duration of speed changes), then I need to pull out the right side of hundreds of frames after first moving them apart enough to allow for changing them if I'm making them longer.
    These animations are different from the rotating reel animations in that they are for laterally moving subjects that are long streams of moving graphics and photos.
    I read about "clip nesting", but I think that only applies to clips or groups of clips that are the same, whereas my clips are each from different imported layers times 125 or so, consecutively placed one after another to create the laterally moving stop frame animation.
    Now I've tried johnbmx4christ's alternate method of creating rotations that was just posted on the other thread about the rotation distortion, but that method results in the same oblong distortion and messed up looking horizontal interlace lines.
    What a can of worms.
    Thanks,
    digi

Maybe you are looking for