A question about the analytical function used with the GROUP BY clause in SHORT

Hi all

I created the following table named myenterprise
CITY       STOREID    MONTH_NAME TOTAL_SALES            
---------- ---------- ---------- ---------------------- 
paris      id1        January    1000                   
paris      id1        March      7000                   
paris      id1        April      2000                   
paris      id2        November   2000                   
paris      id3        January    5000                   
london     id4        Janaury    3000                   
london     id4        August     6000                   
london     id5        September  500                    
london     id5        November   1000
If I want to find which is the total sales by city? I'll run the following query
SELECT city, SUM(total_sales) AS TOTAL_SALES_PER_CITY
FROM myenterprise
GROUP BY city
ORDER BY city, TOTAL_SALES_PER_CITY;
that works very well and produces the expected result, i.e.
CITY       TOTAL_SALES_PER_CITY   
---------- ---------------------- 
london     10500                  
paris      17000            
Now in one of my books SQL (Mastering Oracle SQL) I found another method by using the SUM, but this time as an analytic function. Here's what the method of the book suggests as an alternative to the problem:
SELECT city, 
       SUM(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
FROM myenterprise
GROUP BY city
ORDER BY city, TOTAL_SALES_PER_CITY;
I know that the analytic functions are executed after the GROUP BY clause has been transformed completely and Unlike regular aggregate functions, they return their result for each line belonging to the partitions specified in the partition clause (if there is a defined partition clause).

Now my problem is that I do not understand what we have to use two functions SUM? If we only use one only, i.e.
SELECT city, 
       SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
FROM myenterprise
GROUP BY city
ORDER BY city, TOTAL_SALES_PER_CITY;
This generates the following error:
Error starting at line 2 in command:
SELECT city, 
       SUM(total_sales) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
FROM myenterprise
GROUP BY city
ORDER BY city, TOTAL_SALES_PER_CITY
Error at Command Line:2 Column:11
Error report:
SQL Error: ORA-00979: not a GROUP BY expression
00979. 00000 -  "not a GROUP BY expression"
*Cause:    
*Action:
The error is generated for the line 2 column 11 which is, for the expression SUM (total_sales), well it's true that total_sales does not appear in the GROUP BY clause, but this should not be a problem, it has been used in an analytical function, so it is evaluated after the GROUP BY clause.

So here's my question:

Why use SUM (SUM (total_sales)) instead of SUM (total_sales)?


Thanks in advance!
:)





In case you are interested, that's my definition of the table:
DROP TABLE myenterprise;
CREATE TABLE myenterprise(
city VARCHAR2(10), 
storeid VARCHAR2(10),
month_name VARCHAR2(10),
total_sales NUMBER);

INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('paris', 'id1', 'January', 1000);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('paris', 'id1', 'March', 7000);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('paris', 'id1', 'April', 2000);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('paris', 'id2', 'November', 2000);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('paris', 'id3', 'January', 5000);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('london', 'id4', 'Janaury', 3000);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('london', 'id4', 'August', 6000);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('london', 'id5', 'September', 500);
INSERT INTO myenterprise(city, storeid, month_name, total_sales)
  VALUES ('london', 'id5', 'November', 1000);
Edited by: dariyoosh on April 9, 2009 04:51

It is clear that thet Analytics is reduntant here...
You can even use AVG or any analytic function...

SQL> SELECT city,
  2         avg(SUM(total_sales)) OVER (PARTITION BY city) AS TOTAL_SALES_PER_CITY
  3  FROM myenterprise
  4  GROUP BY city
  5  ORDER BY city, TOTAL_SALES_PER_CITY;

CITY       TOTAL_SALES_PER_CITY
---------- --------------------
london                    10500
paris                     17000

Tags: Database

Similar Questions

  • I posted a question about the FBI virus. How to get rid of him. I ' v was only one answer. Someone to give here can help me with that. I am 62 and although I use my high tower dyly I'm not a COMPUTER technician.

    I posted a question about the FBI virus. How to get rid of him. I ' v was only one answer. Someone to give here can help me with that. I'm 62, and I'm not a computer genius. I have some [eratly helpgetting need to get rid of the virus of the FBI. MS antivirus and scan not work or identify it.  Help, please! 1

    Emisoft is a desperately slow download, as I just discovered.

    You can simply run Malwarebytes and it...

    http://www.Microsoft.com/security/scanner/en-us/default.aspx

  • Question about the database to use with ESX and Labmanager

    Hello

    Finally my company is buying a permit for Labmanager and ESX server using Labmanager to our tests.

    We had a question about the database that we use for the actual installation.

    Could we use MY - SQL? Or that we have the olbigation to install a SQL or Oracle DB for the whole system to work?

    We prefer to use MY_SQL because it is open-source and will cost less to use for us.

    Thanks in advance for the answer and please excuse my bad English, I'm french spoke first.

    Lafa91

    Montreal.

    Lab Manager installs SQL Express as part of the installation and use. If you install also Virtual Center as part of your deployment of Lab Manager (do not use an existing VC server), you can use the database SQL Express is included for small installations of ESX, but MY SQL is not an option. You can search the databases supported in the installation guide for what version you deploy.

  • I have a question about the time machine. I recently updated my Quicken 2015 and there was something wrong with the update. Can I go back in just the Quicken file and restore it until I downloaded the update do I have to restore the entire

    I have a question about the time machine. I recently updated my Quicken 2015 and there was something wrong with the update. Can I come back in all the Quicken file and restore from time Machine before I downloaded the update to do, I need to restore the entire computer?

    Yes, you can just restore this file or application. Use Time Machine to back up or restore your Mac - Apple Support

  • Ask questions about the functionality of EA8500 MU-MIMO

    Dear Linksys

    I bought EA8500, and it arrived today.

    I have two questions about the functionality of MU-MIMO of EA8500 AP.

    1. I want to compare the performance between SU-MIMO and MU-MIMO, but there is no option to control this feature in the router admin page. Is that one of the possible ways?

    2 EA8500 supports 1733 Mbps wireless speed, but it resembles the speed of 1 Gbps ethernet cable.

    This router supports really speed 1 Gbps ethernet? or y at - it an option to support more throughput as the aggregation of links?

    Thank you

    Hi, hyeonu. For your first query, it is not possible because there is no option to disable the feature of MU-MIMO on your Linksys EA8500 router. In addition, with regard to your second, you can get a higher throughput of 1 Gbps since this is the maximum capacity of your ethernet connection.

  • A question about the insertion of the localTimeStamp returned the value into a timestamp with time zone column

    Hello

    Oracle version: Enterprise Edition Release 12.1.0.1.0 - 64 bit

    OS: CentOS 4.6 X86_64                  

    I have a question about the localTimeStamp function. According to the documentation for this function is
    the same thing as current_TimeStamp except that the returned value does not include the time zone.

    Consider the following example:

    SQL > create table tmptab (colval timestamp with time zone not null);

    Table created.

    SQL > insert into tmptab (colval) values (localTimeStamp);

    1 line of creation.

    SQL > select t1.colval, tmptab from t1;

    COLVAL

    ---------------------------------------------------------------------------

    24 JANUARY 14 09.45.42.253732 H + 01:00

    SQL >

    Why introduce the foregoing did not fail? the data type of the column in my table colval expects a timestamp with time zone

    during each which inserts as I understand (correct me if I'm wrong) is not provided by the localTimeStamp function.

    Could someone kindly tell me what I misunderstood?

    Thanks in advance,

    dariyoosh wrote:

    Hello

    Oracle version: Enterprise Edition Release 12.1.0.1.0 - 64 bit

    OS: CentOS 4.6 X86_64                  

    I have a question about the localTimeStamp function. According to the documentation for this function is
    the same thing as current_TimeStamp except that the returned value does not include the time zone.

    Consider the following example:

    SQL > create table tmptab (colval timestamp with time zone not null);

    Table created.

    SQL > insert into tmptab (colval) values (localTimeStamp);

    1 line of creation.

    SQL > select t1.colval, tmptab from t1;

    COLVAL

    ---------------------------------------------------------------------------

    24 JANUARY 14 09.45.42.253732 H + 01:00

    SQL >

    Why introduce the foregoing did not fail? the data type of the column in my table colval expects a timestamp with time zone

    during each which inserts as I understand (correct me if I'm wrong) is not provided by the localTimeStamp function.

    Could someone kindly tell me what I misunderstood?

    Thanks in advance,

    Then, when you do

    create table t (neck DATE);

    Insert into t (to_date ('1st January 2014', ' mon-dd-yyyy "");)

    Are you surprised that it works? After all a DATE column contains a time component, you do not provide: but he

    works and gives you 00:00:00 as the component "hour".

    Similarly, the timezone component is being developed to automatically with, I think, time zone of your system.

  • I have a question about the functionality of Oracle Identity Manager...?

    Hi friends
    I have a question about the features of Oracle Identity Manager.
    Here's my question:
    Self-management is possible network passwords (reset / unlock) with Oracle Identity Manager 9.1.0.2

    Very grateful.

    What Kevin suggested this means that you are managing accounts and their password by IOM. If your condition is the same then follow:

    Re: error during password reset using the self-service portal

  • A few questions about the use of data and Cliq

    I have the cliq, however I chose to not get 3G (so I bought full fare). So I have a few questions about the phone and the use of 3G / 2 G/Edge:

    1 - is possible to disable completely the 2G / 3 G/Edge? I know you can switch between them, but are anyway just tell the phone to stop using them altogether since I'm not subbed to the service?

    2. when the update takes place, I guess we'll have to reconnect motoblur and etc, but if I don't have 3 G will I have motoblur connection problems after the update? Or he keeps the latest wifi settings so that it would connect to wifi to connect. When I first got my phone it was not a problem b/c I had 3G for the first month.

    I hope that makes sense, thanks!

    To stop all the data, I would like to download an application called APNDroid. He cut them all down. When you log on to blur you have 3G or WIFI doe this without getting a timeout error. During the process of setting up your Blur account, you can press the menu button and set up your wifi to work, this will connect you to Blur and your phone will be connected to the blur. If I were you I would be rethinking to do a data plan since you are really losing out on most of your main features of phones. It's your choice, however.

  • An error occurred when DNS was questioned about the resource record (SRV) service location used to locate a domain controller Active Directory (AD DC) for the domain 'HAMI. LOCAL ".

    An error occurred when DNS was questioned about the resource record (SRV) service location used to locate a domain controller Active Directory (AD DC) for the domain 'HAMI. LOCAL ".

    The error was: "an existing connection was to be closed by the remote host".
    (0 x 00002746 WSAECONNRESET error code)

    The query was for the SRV record for _ldap._tcp.dc._msdcs. HAMI. LOCAL

    Hello

    Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public. Please post your question in the Forums TechNet Windows 7 Technet.

    Here is the link:
    http://social.technet.Microsoft.com/forums/en-us/w7itpronetworking/threads

    Hope this helps

  • Person to contact with questions about the presentation of the app world

    If I have a question about the app that I submitted, anyone knows how do I contact someone about this? I can't find anything on the site and respond to notification emails gets me nowhere.

    Hey miss breeder,.

    that will be tough. If you browse the App World his hell out there because of the new development forums and people have a lot of problems with it. I've read people were emailing RIM all week and no responses were received. But if you post a question here MShom (one of the moderators) usually responds in a timely. The support email is [email protected] I believe. Good luck!

  • Got a legal question about the installation of Adobe Photoshop Elements.  How to get help from Adobe using a chat session?

    Got a legal question about the installation of Adobe Photoshop Elements.  How to get help from Adobe using a chat session?

    AdobeTomFaith

    If your program is Photoshop Elements, then you have posted in the wrong forum. Some how your son got posted in the Forum Adobe Premiere elements (video editing). Please re-post your thread in the Adobe Photoshop elements Forum.

    Photoshop Elements

    Wherever your son is, please include Adobe Photoshop Elements version and operating system and the description of the installation problem (error messages, stage of failure, etc.)

    Support Adobe seems to be limited to Adobe cat and is classically limited to the current version which is 13. Then, you the best avenue to success is likely to be through the Adobe Photoshop elements Forum. But that shouldn't stop you trying to determine what kind of support you can get from Adobe cat on your question.

    I would offer this link that is specific for Adobe Chat download and installation

    Contact the customer service (this is not the same destination as shown in a previous post in your thread)

    This link is specifically designed for

    Photoshop Elements

    Download, installation, setting up

    Download and installation

    Panel discussion

    (18:00 - Friday 7 pm Sunday)

    Thank you.

    RTA

  • Questions about the export of PDF with India CS5.5

    Hey all,.

    A few questions about the export to PDF of the most recent version of India.

    First of all, I noticed it seems to take much more time to access a PDF file. Any suggestions about how to speed up the process? It took 8 minutes to generate a PDF low resolution (for printing) of a document of 24pp with placed images and vector graphics. Wow, that's a long wait, especially for evidence.

    Second, the background task... If I get it will make this PDF of 8 minutes and then more work on the document, which is exactly in the PDF? Usually, I have save before making a PDF or printing. Thus, the latest version is saved which will be in the PDF?

    (Either incidentally, this ability to work on the doc while generating a PDF file seems kind of weird. Generally, we do a PDF for proofing, or even for printing, when any changes have been made and that everything is "final". Therefore, I see no advantage in being able to work on my document while it is making a PDF file, I am probably once your revisions for the moment. I must say that I like the progress bar that you get when you perform an interactive PDF, as you know that you can not work on the document when it is on the screen...)

    Thank you as always.

    Good, people. Wanted to just follow this and post my results. It turns out that the problem is somewhere in the Illustrator file. I never had the time to guess what work plan was the culprit. Other India files PDF files is transparent and not a lot of time.

    No resolution, unfortunately, just good to know that it is not all India files on my system. Phew!

    THANK YOU for your advice.

  • Question about the differences in commands

    Hey guys -.

    I just had a few questions about the differences between orders that seem to perform the same function.  Can you let me know if an order is more preferable to the other and what the difference is.  I would really appreciate it as it I currently practice some INE laboratories and I see that orders change from lab to lab.  Thanks advance!

    1. When you write a static NAT for specific host 1 - is - this important if I understand the 32 subnet?

    EX: static (inside, outside) 1.1.1.1, 2.2.2.2 VS static (inside, outside) 1.1.1.1 2.2.2.2 netmask 255.255.255.255

    2. when I'm setting up a router as a CA server and it is necessary to "export" the key, whatever my method of exporting the key?  If so, in which method call for which solution?

    EX: key export cryptographic rsa ciscox pem URL nvram: cisco VS. exporting key 3des cryptographic ciscox pem 3des rsa terminal cisco

    3. If I have to mark a packet with a DSCP of X value, matter if I use the 'set dscp' VS 'set ip dscp?  If so, what is the difference?

    FXY

    Policy-map X

    class X

    the dscp X value

    VS

    Policy-map X

    class X

    X ip dscp value

    I guess pertaining to 2, if i was speaking in terms of from a cisco router to another cisco router - would terminal be acceptable?

    Yes, the "Import cryptographic key" command can take a url and also from the terminal entrance. In this terminal case wil is much easier.

    --
    Don't stop once you have upgraded your network! Improve the world by lending money to low-income workers:
    http://www.Kiva.org/invitedBy/karsteni

  • HTML (Web), I have a question about the models.

    Hello CC animate developers.

    New features are really good.

    HTML (Web), I have a question about the models.

    <! DOCTYPE html >

    < html >

    < head >

    < meta charset = "UTF-8" >

    < title > $TITLE < /title >

    < meta name = "ad.size" content ="width = $WT, height = $HT" > "

    $CREATEJS_SCRIPTS

    $SCRIPT_START

    var canvas, stage, exportRoot;

    function init() {}

    $CJS_INIT

    }

    $PLAYSOUND

    $SCRIPT_END

    < script type = "text/javascript" >

    "clickTAG" var = "";

    < /script >

    < / head >

    < onload = "init (); the body"style =" background-color: #D4D4D4; " margin: 0px; ">

    < a href = "javascript:window.open (window.clickTag)" >

    < div style = "position: absolute;" cursor: pointer; box-sizing: border-box; border: 1px solid #000000; overflow: hidden; height: $HTpx; Width: $WTpx; Background: rgb (255, 255, 255.0); "> < / div >

    < canvas id = "$CANVAS_ID" width = "$WT" height = "$HT" style = "background-color: $BG" > < / canvas >

    < /a >

    < / body >

    < / html >

    In the example above, the model;

    < Meta name = "ad.siz of" content = "width = $ WTI height = $ HT" > "

    and

    < Div style = "position: absolute;" cursor: pointer; box-sizing: border-box; border: 1px solid # 000000; overflow: hidden; height: $HTpx; Width: $WTpx; Background: rgb (255, 255, 255.0); "> < / div >"

    I use labels. But these tags in the template and import, it gives an error does not occur.

    I think it was a mistake. I want to help in this regard.

    $ HT or Properties $WT , I get an error when I use elsewhere.

    I think I should be able to use anywhere I want.

    The same problem here - I worked around by some DRM models with different values of ad.size, but it's a solution quite short-seight

    Also - you are not able to create the model with transparent background by removing style = "" background-color: $BG ' as it also throws errors - is the only solution that I managed to get updates style = "background-color: $BG; background: none; ", but it's a really bad way of coding things.

    It would be really great to have freedom in changing patterns.

  • A few Questions about the advanced Actions window

    Hello

    I have a few questions about the progress of the Actions (using the version of track CP7)

    1. What is the function of the action to "continue?"   Out of the peak action and advance the playback cursor?

    2. What does mean this comment "Nested calls to action advanced is a nice improvement."? Is the advanced decision at the top of a page of action tabs?

    3. What is the function of the option "custom" in the IF statement - "preform action if - custom", it doesn't seem to do anything for me?

    4. where can I get information about the timeline / playhead interaction with advanced actions, i.e. where the playhead is going again at the beginning of the slide. slide custom question - display button, e.g. verification of responses, comments - when all the objects are at the beginning of the timeline. I'm looking more for the read head of infromation functionality rather than how to implement this type of question.

    Thank you

    Donal.

    Continue: If an advanced standard action is triggered by a button, this will not trigger the playback head. If you want out, you can use continues. Continue can also be a choice in a conditional action, when one orders branching has nothing to special, but in advance. Continuous is also the "dummy" statement/command (this is the official name of a line in the dialog box advanced actions) If a statement has become unusable due to some reasons, it will be replaced by continue

    There is no nested call stocks advanced possible right now, one of my many feature requests. It would be sort of a subroutine that you can use over and over again, instead of having to create each time when necessary.

    A decision is one of the conditions to be an advanced conditional action. They allow to create more complex actions, as a loop or arrays are not possible. All decisions are executed in sequence and always.

    Custom: is a combination of or but it is rather limited, because you cannot use parentheses.

    I guess you'd better visit my blog if you want to learn more about the advanced actions.

    http://blog.lilybiri.com/

    I also did several Webinars on stocks advanced, last this afternoon (on the sharing of the actions) for Adobe. They are all available on request.

    Lilybiri

Maybe you are looking for

  • Satellite P300-156 very slow

    Hi people, my laptop is very slow, that pop ups always happen even on the highest setting and like crazy when I bought it I do not have any disk backup!

  • Guarantee rules to recreate the image

    Hello I recently bought a Lenovo ideapad Z580 (in India). It comes with Windows 7 Home Basic Edition. I want to know if the hardware warranty will void if I remove the preinstalled OS (I'll keep the intact although OEM partition) and install another

  • HP Probook 455 g1: HP Probook 455 g1 - A4 to A10 upgrade?

    Hello I recently bought a HP Probook 455 g1, running an AMD A4 - 4300M.  Would it not possible/feasible to upgrade at A10 - 5750M?  I heard it can use the same socket, but may have problems...?  Or I will have to settle a few flavors of A8? Thanks in

  • View files on CRIO

    Hello I've been using the RT file write text found in the following link. This shows how to read and write to a file on the cRIO text and what I want to do is to check that the file is created and that the appropriate data is stored. How would I go a

  • minimum partition size for installing windows xp pro on a 80 GB hard drive

    I need to reinstall windows xp pro on my computer that I had a virus that slowed down the entire system. If I partition the hard drive to install the software for xp, what s the minimum space necessary to do incase I get a virus and have to reinstall