...having without group by...

Hi,
I have a situation to pull data based on some condition.
table looks like this.
Region Countries Payments in millions
Asia India $10
Asia China $30
Europe France $50
Asia Singapore $20
Europe UK $20
NorthAmerica Canada $25
SouthAmerica Mexico $5
SouthAmerica Brazil $5
I want to see data on regional basis. and want to group regions whose amts are less than 50 with name "Others". like
Asia 60
Europe 70
Others 35 (ie NorthAmerica(25) + SouthAmerica(10))
I wrote a query like this...
Select Region, Sum(Payments)
From Reg_Payments
group by Region
having Sum(Payments) > 50
union
Select 'Other', Sum(Payments)
From Reg_Payments
group by 'Other'
having Sum(Payments) < 50
This second query giving error
So I modified this way.
Select Region, Sum(Payments)
From Reg_Payments
group by Region
having Sum(Payments) > 50
union
Select 'Other', Sum(Payments)
From Reg_Payments
Where Region in (Select Region
from From Reg_Payments
group by Region
Having Sum(Payments) < 50)
group by 'Other'
I am getting the data what I want....but Can you guys suggest to do this in better way...Please suggest ASAP..
Thanks a lot...
- Datla

This..?
SQL>select case when sm > 50 then region
  2             else 'Others'
  3        end region,sum(sm) payments
  4 from
  5     (select region,sum(payments) sm
  6      from tt
  7      group by region)
  8 group by case when sm > 50 then region
  9               else 'Others'
10          end;
REGION                 PAYMENTS
Asia                         60
Europe                       70
Others                       35                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Resizing multiple objects without grouping them

    In AppleWorks Draw one could just band or shift select a group of objects and resize them.
    Is there a way of doing this in Pages without having to group everything first?

    No, you have to group first.

  • Nested group function without group xmlagg

    I am getting nested group function without group by xmlagg when using the xmlagg function inside another xmlagg function. Find the table structure and sample data here,
    CREATE TABLE "TEST_TABLE"
       ("KEY" NUMBER(20,0),
        "NAME" VARCHAR2(50 ),
        "DESCRIPTION" VARCHAR2(100 )
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (1,'sam','desc1');
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (2,'max','desc2');
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (3,'peter',null);
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (4,'andrew',null);
    select
            XMLSerialize(document
            xmlelement("root",
             xmlagg(
               xmlelement("emp"          
               , xmlforest(Key as "ID")          
               , xmlforest(name as "ename")
               , xmlelement("Descriptions", 
               xmlagg(
                  xmlforest(description as "Desc")
           ) as clob indent
           ) as t   
          from test_table;Then i removed the xmlagg function from the above select query and used xmlelement instead
      select
            XMLSerialize(document
            xmlelement("root",
             xmlagg(
               xmlelement("emp"          
               , xmlforest(Key as "ID")          
               , xmlforest(name as "ename")
               , xmlelement("Descriptions",            
                  xmlforest(description as "Desc")
           ) as clob indent
           ) as t   
          from test_table;This is working fine, but xml created with empty elements for Descriptions element for key 3 and 4 which has null values. I need don't need Descriptions element in the xml when it has null value. Please help me to resolve this.

    You can do it with a correlated subquery :
    SQL> select xmlserialize(document
      2           xmlelement("root",
      3             xmlagg(
      4               xmlelement("emp"
      5               , xmlforest(
      6                   t.key as "ID"
      7                 , t.name as "ename"
      8                 , (
      9                     select xmlagg(
    10                              xmlelement("Desc", d.description)
    11                              order by d.description -- if necessary
    12                            )
    13                     from test_desc d
    14                     where d.key = t.key
    15                   ) as "Descriptions"
    16                 )
    17               )
    18             )
    19           ) as clob indent
    20         )
    21  from test_table t;
    XMLSERIALIZE(DOCUMENTXMLELEMEN
    <root>
      <emp>
        <ID>1</ID>
        <ename>sam</ename>
        <Descriptions>
          <Desc>desc1_1</Desc>
          <Desc>desc1_2</Desc>
          <Desc>desc1_3</Desc>
        </Descriptions>
      </emp>
      <emp>
        <ID>2</ID>
        <ename>max</ename>
        <Descriptions>
          <Desc>desc2_1</Desc>
          <Desc>desc2_2</Desc>
          <Desc>desc2_3</Desc>
        </Descriptions>
      </emp>
      <emp>
        <ID>3</ID>
        <ename>peter</ename>
      </emp>
      <emp>
        <ID>4</ID>
        <ename>andrew</ename>
      </emp>
    </root>
    Or an OUTER JOIN + GROUP-BY :
    select xmlserialize(document
             xmlelement("root",
               xmlagg(
                 xmlelement("emp"          
                 , xmlforest(
                     t.key as "ID"
                   , t.name as "ename"
                   , xmlagg(
                       xmlforest(d.description as "Desc")
                       order by d.description -- if necessary
                     ) as "Descriptions"
             ) as clob indent
    from test_table t
         left outer join test_desc d on d.key = t.key
    group by t.key
           , t.name
    ;Edited by: odie_63 on 11 juil. 2012 14:54 - added 2nd option

  • Nested Group Function without Group By Problem

    Hey everyone,
    I have 3 tables as below:
    TABLES
    ITEM (Item_no, Item_price, desc)
    DeliveryItem (delivery_no, item_no, quantity)
    Delivery (delivery_no, delivery_date)
    SELECT desc, MAX(SUM(quantity)) FROM DeliveryItem, Item, Delivery WHERE Item.item_no = DeliveryItem.item_no AND Delivery.delivery_no = deliveryitem.delivery_no;
    And I'm trying to output description of most delivered item but I got an error like SQL Error: ORA-00978: nested group function without GROUP BY. Could you help me to fix my code?
    Thanx

    Hi,
    DESC is not a good column name; you could get errors if the parser thinks it means DESCending. I used DESCRIPTION instead, below.
    I think the best way is to do the SUM in a sub-query, lkike this:
    WITH     got_r_num     AS
         SELECT       item_no
         ,       SUM (quantity)     AS total_quantity
         ,       RANK () OVER (ORDER BY  SUM (quantity) DESC)     AS r_num
         FROM       deliveryitem
         GROUP BY  item_no
    SELECT     i.description
    ,     r.total_quantity
    FROM     got_r_num     r
    JOIN     item          i     ON     r.item_no     = i.item_no
    WHERE     r.r_num     = 1
    ;If you want to do it without a sub-query:
    SELECT       MIN (i.description) KEEP (DENSE_RANK LAST ORDER BY SUM (di.quantity)
                        AS description
    ,       MAX (SUM (quantity))     AS total_quantity
    FROM       deliveryitem     di
    JOIN       item          i     ON     d1.item_no     = i.tiem_no
    GROUP BY  i.description
    ;If you do nested aggegate functions, then every column in the SELECT clause must be an aggregate applied to either
    (a) another aggregate, or
    (b) one of the GROUP BY expressions.
    That's why you got the ORA-00937 error.
    This second approach will only display one row of output, so If there is a tie for the item with the greatest total_quantity, only one description will be shown. The RANK method will show all items that had the highest total_quantity.
    It looks like the delivery table plays no role in this problem, but it there's some reason for including it, you can join it tpo either query above.
    Of course, unless you post test copies of your tables (CREATE TABLE and INSERT statements) I cn't test anything.
    Edited by: Frank Kulash on Nov 6, 2010 10:57 AM

  • TS1468 If all tracks on an album are written by one artist, but have other supporting artists, can I group them all as one album under the original artist without having to group them as a compilation and being called "Various Artists"?

    I'm pretty sure I've tried all the suggestions I've found, but I can't seem to find a satisfactory option.
    I'll use a CD I just bought as an example.  I just bought "The Best of Sergio Mendes", all songs are written by Sergio Mendes, but some include Brasil '66.  iTunes thinks this album is a compilation, but I really just want to group it all as Sergio Mendes rather than Various Artists, but I still want to have the information about which songs include Brasil '66.  For some reason the tab "Sorting" does absolutely nothing, but it seems like the idea behind it would be really useful if it actually worked...  Is there a way of doing this or will I have to settle with a more confusing or less informative option?  I feel like this must be possible, or else it's a pretty big flaw for me as I have a fair few albums this would apply to.
    Thanks in advance for any help.

    Indeed, generally all you need to do is fill in an appropriate Album Artist. For more details see my article on Grouping Tracks Into Albums, in particular the topic One album, too many covers.
    Don't try to use sort fields to merge different things together as it quickly goes wrong. These should be used consistently to make all things with one value sort as if they had a different one, e.g. Bowie, David to make David Bowie sort under B.
    tt2

  • Filters without Groups / Smart Objects

    I want to add a layer of scratches and dust marks that is at the top of the composition without having to create a group or smart object.  I tried creating a black layer with the opacity to 0 then applying a scratches and dusts mark, I also tried a empty smart object with 0 opacity, that didn't work either.  I'm hoping their is a technique to this ?

    then applying a scratches and dusts mark
    Filter > Noise > Dust & Scratches is supposed to help remove such things, not add them, so I’m not sure what exactly you mean.
    A blank Layer (or a white Layer set to Blend Mode Multiply) and painted on in black with appropriate Brush tips with some randomization and Scattering might help.
    Could you post an example of what you are after?

  • Xorg 7.0-rc4 dummy pkg. I'd rather having a group.

    It isn't better create a xorg-7.0 group, instead of a dummy package?
    With a group we can choose easily what to install and what not, as pacman asks if it should "install the whole content" of a group or let we choose one by one.

    I think the I will change xorg 7.0 a little bit to get rid of the dummy package: xorg-server will provide both xorg and x-server. xorg-server depends on most things, but not all. This won't install each and every lib anymore, but most of them will get installed this way. We need to check up on many packages anyways, so it doesn't really matter when a lib is missing because of this: the package needed a rebuild anyways then. A set of groups will be made to make sure users new to arch can install xorg without much problems.

  • Aggregate functions without group by clause

    hi friends,
    i was asked an interesting question by my friend. The question is...
    There is a DEPT table which has dept_no and dept_name. There is an EMP table which has emp_no, emp_name and dept_no.
    My requirement is to get the the dept_no, dept_name and the no. of employees in that department. This should be done without using a group by clause.
    Can anyone of you help me to get a solution for this?

    select distinct emp.deptno,dname
    ,count(*) over(partition by emp.deptno)
    from emp
    ,dept
    where emp.deptno=dept.deptno;
    10     ACCOUNTING     3
    20     RESEARCH     5
    30     SALES     6

  • ORA-00978  without group function

    I've experienced a strange problem with oracle 11g.
    I've retrieved the oracle exception ORA-00978 even if there was no group function in my query.
    I supposed was a problem in the optimizer so I rebuild the tables statistics, after that the query was execute successfully.
    Does anyone has an idea what the problem is?
    Is possible that a bug exists in the 11g optimizer?
    My oracle version is:
    Oracle Database 11g Enterprise Edition 11.1.0.6.0 64bit Production
    the query i tried is:
    SELECT *
    FROM TBCALENDAR Cal,
    VWCALENDARACTIVITY CA,
    VWSE R,
    TBSCHEDULERPARTITION P,
    TBREGION REG,
    TBRESOURCE RES ,
    TBZIPCITY z
    WHERE Res.id=Cal.RESOURCE_ID
    AND R.RESOURCE_ID=RES.ID
    AND Cal.ACTIVITY_ID=CA.ID
    AND CA.SCHEDULING=1
    AND Cal.SCHEDPARTITION_ID IN
    (select item.PARTITION_ID
    from tbidcprofile prof,
    tbidcpartitem part,
    tbschedpartitem item
    where prof.USERPROFILE_ID=4
    and prof.IDCPARTITION_ID=part.PARTITION_ID
    and part.BUSINESSUNIT_ID=item.BUSINESSUNIT_ID
    and part.REGION_ID=item.REGION_ID )
    AND TRUNC(Cal.START_DT)=trunc(sysdate)
    AND P.ID=Cal.SCHEDPARTITION_ID
    AND REG.ID(+)=Cal.WORKREGION_ID
    AND Z.GEOLOCATION_ID(+)=Cal.HOMEGEOLOC_ID;
    VWCALENDARACTIVITY and VWSE are two views, but I can select from them without any problem.
    I've also tried to remove one view at a time an the error occurs only when the query uses both view at the same time.
    Thanks
    Renzo

    user479513 wrote:
    VWCALENDARACTIVITY and VWSE are two views, but I can select from them without any problem.
    I've also tried to remove one view at a time an the error occurs only when the query uses both view at the same time.
    What are the views definition ?
    Nicolas.

  • Can Illustrator CS mask layers without grouping them?

    Windows XP Pro SP2
    Intel Pentium 4 CPU 3.60GHz
    2.75GB RAM
    I draw a lot of complex maps using Illustrator 8 in preference to higher versions. I customarily use a top layer clipping path to mask out the edges and "crop" the image.
    The advantage of Illustrator 8 is that the clipped artwork still rests on its respective layers, allowing me to turn on/turn off whichever layers I desire, while still maintaining the mask.
    As far as I can tell, later versions automatically group (and thus place on the top layer) all items that are masked by the clipping path, meaning that my map layers no longer exist, and the map has lost its funtionality.
    I've been using version 8 for years despite having access to CS but now my company is losing 8 and moving over exclusively to CS. I can't figure out an effective way to maintain the same layer functionality in masked artwork in Illustrator CS.
    The mass of nested layers and sub-layers for each and every object has me lost. It seems over complicated but doesn't offer me anything I can use, instead removing the ability to do what I used to do.
    Is there any way I can still mask my artwork and maintain ungrouped layer functionality in Illustrator CS?

    Any object on a parent layer can mask child layers. Here I selected the topmost path and chose Make Clipping mask from the Layers flyout menu. Masked items remain on their own child layers. If I use the Selection tool (black arrow) and click on a tree, only the tree is selected.
    The interface is surprisingly buggy, even for Illustrator. If it's not working, try Cutting and Pasting in front to get Illustrator to figure out it can use the path for a mask.

  • Using aggregrate functions without group by

    Hi
    I have a query which is
    select empno,deptno,count(*) from emp group by empno,deptno;
    Is there any thing which will help me to return empno,deptno without using group by clause?
    Appreciate your help on the above?
    Thanks & Regards
    Thakur Manoj R

    This will give the same result:
    select empno, deptno, count(*) over (partition by empno, deptno) from emp;If you want to see the number of employees in the same department you could use:
    select empno, deptno, count(*) over (partition by deptno) from emp;But what is your intention? What is wrong about "group by"?
    Edited by: hm on 27.01.2011 00:10

  • GROUP BY without GROUP functions

    I red in Oracle university book that you can use the GROUP BY clause without using a group function in the SELECT list, can someone give me an example using the popular table 'employees' OR 'departments'

    I cannot think of why or how such a query would be useful except it you selected the same column you grouped on you would be doing the equilivent of a select distinct:
    UT1 > select deptno from emp group by deptno;
    DEPTNO
    10
    20
    30
    HTH -- Mark D Powell --

  • Deploying printers without Group Policy

    A little background first, I work for a company with 10+ sites while only 2 sites actually are in a domain. Everyday I am getting work orders for adding a ip printers to every machine because they want to print to any printer within their location. I
    understand the print services within windows server 2008 and how I can deploy them easily through group policy. The problem is the majority do not have the domain infrastructure to do this.
    Which leads me to my question of, how and what would be the most painless way of deploying printers to all computers in particular subnets between sites? Create a batch file to add the printers and run it on the each workstation? Create a network share for
    printers? or it is possible to force adding a new printer over the network without a group policy. Thank you all in advance

    script will be an option...
    http://www.computerperformance.co.uk/powershell/powershell_printers.htm
    http://support.risualblogs.com/blog/2012/02/14/using-powershell-to-create-printers/
    Best,
    Howtodo

  • P2p chat without group

    Hello everybody,
    I am playing with cirrus and would like to set up a p2p chat without netgroup. I have made it work for two peers but when I increase the number of peer I got some problem.
    The design:
    I am using one sendStream per peers (Each of them initialize the sendStream (sendStream.publish("media")) and send a message at a regular interval on this stream). sendStream.send("hello");
    every 10 seconds, the peers register themselves on a amfphp service which keep track of their id (random string), their cirrus peerID and a timestamp.
    at this point they also ask the service for a list of other connected peers (timestamp not older than 11 seconds)
    for each new peers connected (based on the service) every other peers create a recvStream that connect to the sendStream of each other peers. In case the recvStream stop (which happen for some reason ?), I restart it recvStream.play("media").
    The problem:
    When the thirs peers connect, not all peers receive messages;
    I also get a event.info.code == "NetStream.Play.PublishNotify" which I do not why (does not happen when only two peers are connected.
    The solution?
    I wonder whether it is because each sendStream can only handle one recvStream ?

    The main reason is that NetGroup does not handle friends group
    If I set a netgroup to send to my friends on facebook, I will successfully send them a message but in case they want to send a emssage back, they will send to everybody in the group which are not necessarely their friend (not all my friend are friends between each other). With netGroup I have  to create a group for each node and these groups should not be writable by the node's friends.
    imagien  I have ten friends currently connected. it means I have to read from ten groups and I have my own group for me to write to them as a group. Furthermore if I want private message I have to send them through a specific channel.
    It seems that in this case, a direct connection seems as good as netgroup, if not simpler.
    Also since I want to udnerstand how things work, I would like to know whether a sending netstream can have more than one receiver.
    I tried again with more simpler code and it seems that in case of flash peer to peer , netStream can only have one simulatenous suscriber. is it correct?
    Does it means that NetStream.peerStreams is always of length 1 ?
    the documentation does not talk about this and woudl like to know for sure.
    If that is thes case I ll have to have a connection handler channel and maintain peer connection channel for each friends. In which case NetGroup might be easier, but still requires maintaing several netgroup and setting writing access to the node sendign message.
    Note: the friend groups taht I want to setup is not intented to be used for chat (even if it could) but for data in a multiplayer game.
    Thank you for your help,
    Sincrely,
    Oohazard

  • Print-time charting with shared variables on a report without groups...

    hello all,
    I have an interesting conundrum; I am working on a report (Crystal XI) with no groups to it, just several subreports. Presently the report is run weekly and sent to the manager of one of our departments.
    The report itself showcases all areas of the department with total tasks, longest outstanding task, average days outstanding, MTD tasks completed, and YTD tasks completed. Due to the variety of tables the data pulls from, I have it set up as subreports that simply display the data.
    All total, there are 20 different shared variables that have been obtained from 10 different subreports. I have the shared variables set as the running totals from the subreports (hence, all are print time). Since the running totals and all the subreports are time based and are not actually linked to ANYTHING on the main report, I am struggling with how to set up the formulas described in the white paper, "Charting on Print Time Formulas".
    The setting up of the two formulas ({@onchngof} and {@showval}) will be different for my situation, as all of the subreports run off of date information relative to when the report is ran. I've got all of the subreports that the shared variables originate in early in the report; but where to from here?
    Would I set up maybe a date grouping or some other non-essential consistent grouping to make it work? The way this report is, it really doesn't need grouping, because the main report is just a display agent for the subreports...
    As always, any help is greatly appreciated!

    Let me ask couple of questions before trying to resolve this.
    1. The chart you are trying to built is placed in which section and is it on Main report or sub-report of its own. This is needed because if you are trying to access shared variables values in Main report, the section should be below the sub-report placed sections.
    2. Try pacing few test formulas in Main report and make sure the correct values are being pulled in on Main report.
    If you are successfully pulling the variable values on the report, try creating a simple chart in report footer with the values you have pulled and see if its taking you somewhere...
    Would need more information on how those variables are being accessed form sub to main or sub to other sub for example are you making an array of those variables and splitting or bringing it in as separate...

Maybe you are looking for

  • How do i connect my macbook pro to a tv

    how do i connect my macbook pro to a tv

  • PO print error

    Dear experts I am getting the following error while I tried for print preview, I have created the message but it is showing the error status (Red signal). Error details: Message incomplete (seriousness, area, number, or exception missing) Message no.

  • Please i need help in my mobile 6300

    i use a program called mobyexplorer when i try to make hide ,password or any other sitting he showed this message "access to the file system is denied please make sure that you set the access permissions on mobyexplorer to allow read and write access

  • Generic Data Source and InfoPackage Data Selection

    Hello,  I'm trying to extract data from a generic data source (composed of a view joining 4 tables) using the Data Selection Criteria in an infopackage.  Sometimes the selection criteria is ignored and more data is pulled than expected.  The number o

  • Pricing redetermination at the sales order

    Hi , We have mass order inquiry tool which will bring in the sales orders in the system and also updates certain fields defined in the tool. For example if we want to change the pricing date we just enter it & the tool will change it. Now we have a n