Question: Hallo,
I have a join table, said tableA and tableB. tableA have a column called Amount. tableB have a column called refID. I would like to total up the Amount column when refID having the same value. I was using SUM in my query, but it throw me an error:

```
ORA-30483: window  functions are not allowed here
30483. 00000 -  "window  functions are not allowed here"
*Cause:    Window functions are allowed only in the SELECT list of a query.
           And, window function cannot be an argument to another window or group
           function.

```

Here is my query for your reference:

```
select *
from (
       select SUM(A.Amount), B.refId, Rank() over (partition by B.refID order by B.id desc) as ranking
       from table A
       left outer join table B on A.refID = B.refID
)
where ranking=1;

```

May I know is there any alternate solution in order for me to SUM the Amount?

THanks @!

Answer: 
```
  Declare @T table(id int) 
    insert into @T values (1),(2)
  Declare @T1 table(Tid int,fkid int,Amount int)
    insert into @T1 values (1,1,200),(2,1,250),(3,2,100),(4,2,25)

    Select SUM(t1.Amount) as amount,t1.fkid as id from @T t
 left outer join @T1 t1 on t1.fkid = t.id group by t1.fkid

```
I'm a little confused. The query you posted did not have a SUM function anywhere, and performed a self-join of a table named "TABLE" to itself. I'm going to guess that you actually have two tables (I'll call them TABLE\_A and TABLE\_B), in which case the following should do it:

```
SELECT a.REFID, SUM(a.AMOUNT)
  FROM TABLE_A a
  INNER JOIN TABLE_B b
    ON (b.REFID = a.REFID)
  GROUP BY a.REFID;

```

If I understood your question you only wanted results when you have a TABLE\_B.REFID which matches a TABLE\_A.REFID, so an INNER JOIN would be appropriate.

Share and enjoy.