Sunday, 8 September 2013

Display SQL AVG function value on all rows

Display SQL AVG function value on all rows

My oracle table, "invoice" looks like this.
INV_NUM CUST_NUM INV_DATE INV_AMOUNT



8000 1000 23-Mar-08 235.89
8001 1001 23-Mar-08 312.82
8002 1001 30-Mar-08 528.1
8003 1000 12-Apr-08 194.78
8004 1000 23-Apr-08 619.44
I need to write a select query that will diplay the inv_num,inv_amount and
the average inv_amount. The expected output is like this.
INV_NUM INV_AMOUNT AVG(INV_AMOUNT)



8000 235.89 378.206
8001 312.82 378.206
8002 528.1 378.206
8003 194.78 378.206
8004 619.44 378.206
I want the value from the AVG function to be repeated in every row. I
understand that the AVG function returns only a single row. I get an error
when I try this query.
select inv_num,inv_amount,avg(inv_amount) from invoice;
ERROR at line 1: ORA-00937: not a single-group group function
Is there a way to get the avg value to be displayed in every row? I need
some help figuring this out. Thanks.

No comments:

Post a Comment