Help: The AVG function.

A query selecting a number column with data 5537 5367, the AVG of the column returns 5452 instead of 5454. Here is a script for test:
create table test (a number(4));
insert into test values(5537);
insert into test values(5367);
select avg(a) from test;
It shows:
AVG(A)
5452
Thank you in advance

ARe you kidding ?!???
5537 + 5367 = 10904 / 2 = 5452
Maybe some fog on your glasses ?...
Francois

Similar Messages

  • Performance Tuning the AVG function

    Dear All,
    I have a table which is rapidly growing. We have a query which is frequently executed on this table and it utilizes AVG function without a WHERE clause. Is there a way to tune this query?
    I tried to create a Materialized View but Oracle rejects as AVG cannot be used in MV's. Also, it is now really easy at this point in time to rewrite the query.
    Appreciate if anybody can help me out in this situation.
    OS: Windows 2003 EE
    Database: Oracle 10g R2 10.2.0.4
    Sample Table:
    Create table t(id number, name varchar2(30), amt number);
    insert into t select level, 'level - ' || level, level * 100 from dual connect by dual level <= 1000;
    commit;
    Query:
    select avg(amount) from t;
    Thanks for you time.
    - P

    >
    ... and it utilizes AVG function without a WHERE clause
    >
    As Aman stated, a full table scan will be needed for a statement without a WHERE clause.
    See these threads on how to post a tuning request
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HTH
    Srini

  • Yielding the desired number of decimal places using the AVG function in t-sql

    Hello again.  Confused retired hobby coder having trouble setting up a scalar-valued function to return the desired number of decimal places from a AVG query.
    Whenever I run the following script I get the number of decimals I desire:
    Using the above I created a scalar-valued function as follows:
    Running this function as: SELECT [dbo].[TestHCIPartial] (1,3)  my return is -7.
    Can you help me with the function causing it to yield the answer to 6 decimal places?
    Thanks and regards, Minuend.

    You've not specified precision and scale in UDF return type. So you're leaving it to server to interpret it based on default settings
    If you want exactly up to four decimal places tweak udf as below
    ALTER FUNCTION..
    RETURNS decimal(20,4)
    AS
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Rounding the aggregate function in a pivot table

    How do I round the avg(GRADE) when I tried just wrapping it around the avg function I get an error message saying expect aggregate function inside pivot operation
    pivot
    ( avg(GRADE)
    for Column
    in ('1012222','2221112','333113' );
    Thanks for the help.
    Edit : Sorry wasn't very clear all thats shown is the pivot part of the statement.
    Edited by: 836321 on Feb 13, 2011 8:56 AM
    Edited by: 836321 on Feb 13, 2011 8:58 AM

    Hi, and welcome to the forum.
    It is hard to see how your piece of pseudo SQL is related to your subject title.
    There should not be any problem in wrapping ROUND around AVG:
    SQL> select deptno, round(avg(sal)) from emp
    where deptno in (10,20)
    group by deptno
        DEPTNO ROUND(AVG(SAL))
            20            2175
            10            2917
    2 rows selected.Edit: Sorry, did not recognize you query bit. You probably are asking about this:
    SELECT * FROM
       (SELECT deptno, sal FROM emp)
        PIVOT
       (ROUND(AVG(sal)) FOR deptno IN (10 AS Accounting, 30 AS Sales));
    Error at line 4
    ORA-56902: expect aggregate function inside pivot operationSuppose you have to (There might be other ways)
    SQL> SELECT Round(accounting), round(sales) FROM
       (SELECT deptno, sal FROM emp)
        PIVOT
       (AVG(sal) FOR deptno IN (10 AS Accounting, 30 AS Sales));
    ROUND(ACCOUNTING) ROUND(SALES)
                 2917         1567
    1 row selected.Regards
    Peter
    Edited by: Peter on Feb 13, 2011 9:05 AM
    Edited by: Peter Gjelstrup on Feb 13, 2011 9:08 AM

  • Store events in differents tables/ AVG function error

    HI,
    I have a very newbie question that i can't resolve.
    I want to store events in a database, so far so good, but if i define the events on context file like this:
    <wlevs:event-type-repository>
    <wlevs:event-type type-name="Averages">
    <wlevs:properties>
    <wlevs:property name="average_Generator1_ActivePower" type="float"/>
    <wlevs:property name="sum_Generator2_ActivePower" type="int"/>
    <wlevs:property name="max_Substation_Active_Power" type="int"/>
    <wlevs:property name="number_events" type="int"/>
    </wlevs:properties>
    </wlevs:event-type>
    <wlevs:event-type type-name="WindEvent">
    <wlevs:properties>
    <wlevs:property name="generator1_ActivePower" type="int"/>
    <wlevs:property name="generator2_ActivePower" type="int"/>
    <wlevs:property name="substation_Active_Power" type="int"/>
    </wlevs:properties>
    </wlevs:event-type>
    </wlevs:event-type-repository>
    They will be saved in the same table, TupleValues table.
    I try to workaround this situation by defining one of the events as a class and in this case the Oracle CEP create a different table to store this events. But, with this configuration, I have an error on the processor node, most exactly, in the avg function that use a property of the class created. Below there is the context file, the java class and the query in the processor
    #Java class
    public class WindEvent {
         private Integer Generator1_ActivePower;
         private Integer Generator1_AverageExpectedEnergy;
         private Integer Generator2_ActivePower;
         private Integer Generator2_AverageExpectedEnergy;
         private Integer Substation_Active_Power;
         private Integer Substation_AverageExpectedEnergy;
    #context file
    <wlevs:event-type-repository>
    <wlevs:event-type type-name="WindEvent">
    <wlevs:class>oracle.cep.demo.events.WindEvent</wlevs:class>
    </wlevs:event-type>
    </wlevs:event-type-repository>
         <wlevs:adapter id="adapter" provider="csvgen">
              <wlevs:listener ref="channel" />
              <wlevs:instance-property name="port" value="9001" />
              <wlevs:instance-property name="eventTypeName" value="WindEvent" />
              <wlevs:instance-property name="eventPropertyNames"
    value="generator1_ActivePower,generator1_AverageExpectedEnergy,generator2_ActivePower,generator2_AverageExpectedEnergy,substation_Active_Power,substation_AverageExpectedEnergy"/>
         </wlevs:adapter>
         <wlevs:channel id="channel" event-type="WindEvent">
              <wlevs:listener ref="processor" />
         </wlevs:channel>
         <wlevs:processor id="processor">
         </wlevs:processor>
    #query
    <processor>
    <name>processor</name>
    <rules>
    <query id="ExampleQuery">
    <![CDATA[select  avg(substation_Active_Power) as max_Substation_Active_Power, count(*) as number_events from channel [range 60]]]>
    </query>
    </rules>
    </processor>
    If somebody could help in the two questions i will be really grateful

    this is the output of the error:
    <Warning> <Spring> <BEA-2047006> <Work {0} terminated with exception = commonj.work.WorkException: java.lang.RuntimeException: [Adapter:2041010]Event type WindEvent has a property of type int. This tool only supports String, Integer, Long, Float, and Double properties.
    commonj.work.WorkException: java.lang.RuntimeException: [Adapter:2041010]Event type WindEvent has a property of type int. This tool only supports String, Integer, Long, Float, and Double properties.
         at weblogic.work.commonj.CommonjWorkManagerImpl$WorkStatus.setThrowable(CommonjWorkManagerImpl.java:260)
         at weblogic.work.commonj.CommonjWorkManagerImpl$WorkWithListener.run(CommonjWorkManagerImpl.java:198)
         at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    Caused By: java.lang.RuntimeException: [Adapter:2041010]Event type WindEvent has a property of type int. This tool only supports String, Integer, Long, Float, and Double properties.
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl.validateEventType(CSVGenAdapterImpl.java:75)
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl.run(CSVGenAdapterImpl.java:42)
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl$$FastClassByCGLIB$$1d34d8cd.invoke(<generated>)
         at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
         at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
         at com.bea.wlevs.ede.impl.EventManagerAccessorProxy.invoke(EventManagerAccessorProxy.java:30)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at com.bea.wlevs.ede.impl.EventBeanProxy.invoke(EventBeanProxy.java:38)
         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
         at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
         at com.bea.wlevs.adapter.defaultprovider.internal.CSVGenAdapterImpl$$EnhancerByCGLIB$$e60b1b.run(<generated>)
         at com.bea.wlevs.spring.RunnableBeanPostProcessor$RunnableWrapper.run(RunnableBeanPostProcessor.java:118)
         at weblogic.work.commonj.CommonjWorkManagerImpl$WorkWithListener.run(CommonjWorkManagerImpl.java:196)
         at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

  • How to use AVG function to determine difference.

    Hi, I have a basic table where there is an invoice price. I can do the AVG function to find out what the average is, but I need to be able to subtract the difference from each value in the column and submit it as a query. I was wondering if anyone had any advice how I'd do that.
    Thanks,
    Justin

    wrote:user_7000025
    Here is the table in question and the specific instructions:
    Write the query that will show the invoice number, the average invoice amount, and the difference between the average invoice amount and the actual invoice amount.
    INV_NUM CUST_NUM INV_DATE INV_AMOUNT
    8000 1000 23-MAR-04 236
    8001 1001 23-MAR-04 313
    8002 1001 30-MAR-04 528
    8003 1000 12-APR-04 195
    8004 1000 23-APR-04 619test@XE> --
    test@XE> -- Write the query that will show the invoice number, the average invoice amount, and
    test@XE> -- the difference between the average invoice amount and the actual invoice amount.
    test@XE> --
    test@XE>
    test@XE> --
    test@XE> with t as (
    2 select 8000 inv_num, 1000 cust_num, to_date('23-MAR-04','DD-MON-RR') inv_date, 236 inv_amount from dual union all
    3 select 8001, 1001, to_date('23-MAR-04','DD-MON-RR'), 313 from dual union all
    4 select 8002, 1001, to_date('30-MAR-04','DD-MON-RR'), 528 from dual union all
    5 select 8003, 1000, to_date('12-APR-04','DD-MON-RR'), 195 from dual union all
    6 select 8004, 1000, to_date('23-APR-04','DD-MON-RR'), 619 from dual)
    7 --
    8 select inv_num,
    9 cust_num,
    10 inv_date,
    11 inv_amount,
    12 avg(inv_amount) over () as avg_inv_amt,
    13 avg(inv_amount) over () - inv_amount as avg_actual_diff
    14 from t;
    INV_NUM CUST_NUM INV_DATE INV_AMOUNT AVG_INV_AMT AVG_ACTUAL_DIFF
    8000 1000 23-MAR-04 236 378.2 142.2
    8001 1001 23-MAR-04 313 378.2 65.2
    8002 1001 30-MAR-04 528 378.2 -149.8
    8003 1000 12-APR-04 195 378.2 183.2
    8004 1000 23-APR-04 619 378.2 -240.8
    5 rows selected.
    test@XE>
    test@XE>
    isotope
    Update: Good to know the solution worked. You may want to mark the question answered and award points.
    Edited by: isotope on Mar 14, 2009 10:50 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Avg function and problems with it

    I know this may sound stupid since I'm pretty new to Oracle and SQL, but I'm trying to do a query with an average price and it's keeps giving me the error that group function not allowed here. Could someone point me in the right direction here. This is what I have but it keeps giving me that error.
    SELECT productID productName, price
    FROM our_product
    WHERE AVG(price)<price;

    Since the AVG function requires that rows get aggregated, you can't use it like that in a WHERE clause. You could put it in a subquery like this
    SELECT productID, productName, price
      FROM our_product
    WHERE price > (
        SELECT AVG(price)
          FROM our_product
        )It would generally be more efficient, however, to do something like this with the analytic version of AVG
    SELECT *
      FROM (
        SELECT productID,
               productName,
               price,
               AVG(price) OVER () avg_price
          FROM our_product
    WHERE avg_price < priceJustin
    Edited by: Justin Cave on Oct 17, 2009 9:10 PM

  • Please tell me exactly how to remove the AVG search function

    Please tell me exactly how to remove the AVG search function
    ''edited by a moderator for clarity''

    You don't need to repeat yourself dozens of time or use profanity to get help here.
    (1) Disable ALL nonessential or unrecognized extensions on this tab. Not sure what it does? If in doubt, disable:
    orange Firefox button (or Tools menu) > Add-ons > Extensions category
    Use of the links above a disabled extension to restart Firefox if any appear.
    (2) Reset your search providers to Google:
    https://addons.mozilla.org/en-US/firefox/addon/searchreset/
    (3) Check for a user.js file (do this before exiting Firefox, otherwise the settings in that file can undo your cleanup) as described in this article: [[How to fix preferences that won't save]].
    (4) If AVG search took over your new tab page (Ctrl+t), change that as follows:
    (A) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (B) In the filter box, type or paste '''newtab''' and pause while the list is filtered
    (C) Double-click the '''browser.newtab.url''' preference and enter the desired value for your preferred page:
    ''(i) Page thumbnails (default)'' => about:newtab
    ''(ii) Blank tab'' => about:blank
    ''(iii) Built-in Firefox home page'' => about:home
    ''(iv) Any other page'' => full URL to the page
    IMPORTANT: If you have AVG software in your Windows Control Panel, you may also need to remove it there.

  • I am new to LR and have it set up on a Mac desktop and laptop.  On the laptop, the Basic function under Develop simply disappeared.  I am lost.  Help.

    Question:  I am new to LR and have it set up on a Mac desktop and laptop.  On the laptop, the Basic function under Develop simply disappeared.  I am lost.  Help.

    It's a common issue. The Basic panel is merely hidden.
    Hiding/unhiding panels is actually a feature of Lightroom but it is unintuitive - few people know it exists - so most newcomers are thrown when a panel somehow gets hidden.
    Right-click anywhere in the right hand side panel area and a context menu will appear.
    Click the Basic option to make the Basic panel re-appear.

  • The search function in the itunes store does not work.  It will accept a request and suggest searches but then it locks up and will not search.  Clicking on the magnifying glass or a suggested search does nothing.  Re-installing itunes has not helped.

    The search function in the itunes store does not work.  It will accept a request and suggest searches but then it locks up and will not search.  Clicking on the magnifying glass or a suggested search does nothing.  Re-installing itunes has not helped.

    everything you stated here is exactly what i have done and have got nowhere. i have windows 7 64 bit on a hp 8 g of ram desktop. im also looking for help

  • Hi, i installed ios 5 for my iphone 4 and the camera function on lock screen was on the first few days , now it doesn't show the lock screen . is there any change i can do . Pls help me to solve the issue.

    hi, i installed ios 5 for my iphone 4 and the camera function on lock screen was on the first few days , now it doesn't show the lock screen . is there any change i can do . Pls help me to solve the issue.

    nishaadp wrote:
    ... it stucks with the apple logo ,  nothing works. Is anything i can do?
    See Here for
    Frozen or unresponsive iPhone

  • Just installed a HP Color Laserjet CM2320nf MFP printer, at the same time I upgraded to Lion. It prints fine, but I cannot use the scan functions.  I downloaded the most recent driver! Any help would be appreciated.

    Just installed a HP Color Laserjet CM2320nf MFP printer, at the same time I upgraded to Lion. It prints fine, but I cannot use the scan functions.  I downloaded the most recent driver! Any help would be appreciated.

    HP says that the drivers for your all in one print/scanner are downloadable from apple. For the scanner to use preview. image capture or the scan icon from the print driver queue.  I don't know how old your HP is, but I know that the newer Os from apple don't support a lot of older printers. You might be able find a third party driver that could work.

  • My daughter has just bought me an iPad 2 from Dubai and set it all up for me but unfortunately the iMessage function doesn't seem to work. We keep getting messages,when trying to activate it, that there is a network connection problem - help!

    My daughter has just bought me an iPad 2 from Dubai and set it all up for me but unfortunately the iMessage function doesn't seem to work. We keep getting messages,when trying to activate it, that there is a network connection problem - help!

    Thank you both for your responses but my daughter was reassured by the salesman in the iStyle store (official Apple store in the UAE) that iMessages would work but conceded that FaceTime wouldn't. My iTunes account is registered in the uk and my daughter's iPhone has iMessages even though she bought it (and uses it) in Dubai. Can anyone else throw any light on this?

  • HT4623 I've installed the update and even resorted to the restore function. My phone doesn't work not. My screen shows a graphic of the usb connector with an arrow pointing towards and Itunes icon. It will do nothing else! HELP

    I've installed the iPhone update and now my phone doesn't work. I even chose the restore function. It went through all that and it still just shows the graphic of the usb and an arrow and the itunes icon. Help!

    Yes, I connected the phone to my iMac which is the original computer it is backed up on. From iTunes I had no option except to restore, which I did. Still no luck. Still just see the graphic. :-(

  • The InitCVIRTE function is not listed in the NIDAQ function reference online help? Why? and where can I find a description of this function?

    the InitCVIRTE function is not listed in the NIDAQ function reference online help? Why? and what does she do?and where can I find a description of this function? Can i use this function with visualc++ 6.0?

    The InitCVIRTE function is in the CVI run time engine (cvirte.dll)..not part of NI-DAQ.
    Applications written or using CVI may call this function..
    How are you running into this ?
    From the CVI help...
    This function performs initialization of the CVI Run-Time Engine. It is needed only in executables or DLLs that are linked using an external compiler. Otherwise, it is harmless.
    It should be called in your main, WinMain, or DllMain, function. The parameter values you should pass depend on which of these three functions you are calling InitCVIRTE from. The following examples show how to use InitCVIRTE in each case.
    If you are using main, your code should be as follows.
    int main (int argc, char *argv[])
    if (InitCVIRTE (0, argv, 0) == 0)
    return -1; /* out of memory */
    /* your other code */
    return 0;
    If you are using WinMain, your code should be as follows.
    int __stdcall WinMain (HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszCmdLine,
    int nCmdShow)
    if (InitCVIRTE (hInstance, 0, 0) == 0)
    return -1; /* out of memory */
    /* your other code */
    return 0;
    If you are creating a DLL, you must call InitCVIRTE and CloseCVIRTE in your DllMain function, as in the following.
    int __stdcall DllMain (void *hinstDLL, int fdwReason,
    void *lpvReserved)
    if (fdwReason == DLL_PROCESS_ATTACH)
    if (InitCVIRTE (hinstDLL, 0, 0) == 0)
    return 0; /* out of memory */
    /* your other ATTACH code */
    else if (fdwReason == DLL_PROCESS_DETACH)
    /* your other DETACH code */
    CloseCVIRTE ();
    return 1;
    NOTE: The prototype for InitCVIRTE is in cvirte.h, not
    utility.h.
    NOTE: In CVI 4.0.1, this function was expanded from one to
    three parameters. Executables and DLLs that were
    created using the one-parameter version of the function
    will continue to work properly.
    /*-------------------- Prototype ---------------------*/
    int InitCVIRTE (void *HInstance, char *Argv[], void *Reserved);
    Nandan Dharwadker
    Staff Software Engineer
    Measurement Studio Hardware Team

Maybe you are looking for

  • Errors in B2B.log

    I have pointed out the errors in bold in my b2b.log,please comment on this . 2006.10.05 at 17:52:12:223: B2BStarter thread: B2B - (DEBUG) Repository:constructCertSQL SELECT cert.ID, cert.CLASSTYPE FROM TIP_Certificate_ra cert, TIP_Party_ra party, TIP

  • Simple keyboard commands not working in CS6..?

    Am no longer able to navigate around a large document by pressing the space bar (changing the cursor temporarily to the hand tool) or zoom in or out by using command-space bar or option-command-space bar. In both Illustrator and Photoshop. I'm hoping

  • My messaging app won't open!! Help!!!!

    messaging isn't opening on my iPod touch 5th generation. When I tap the app, it shows a blank screen for a while then exits the app. I hav tried restarting my iPod, and even changed the wifi DNS. What else can I do?

  • 160gb Classic wont sync music

    My 160gb ipod classic , works but when i try to upload songs it wont work and tells me its corrupt. It also freezes my itunes for like a minute. I then restore it and now it won't work but no corrupt warning. Any ideas on what i can do?

  • Porque mi ipod no quiere configurar  apple id

    mi ipod no quiere configurar  apple id dice que no se puede conectar a itunes