Hallo everyone,
I am facing a simple and at the same time complicated SQL query problem. I have a table as follow:
Code:
School Name donation_amount
-------------------------------------------------
School_01 Ratna 20
School_01 Ratna 30
School_01 Lena 45
School_02 Ratna 55
School_02 Bob 10
School_03 Peter 5
I would like to list all the schools. To each school, it shall have the number of donation processes from OTHER schools:
Code:
Schule Number
-----------------------
School_01 3
School_02 4
School_03 5
For example, for School_02, it results 4 as the number of the donation processes(3 donation processes from School_01 and 1 from School_03)
How can I produce the SQL for this?

I was thinking, for this problem, I would have to do a GROUP BY on School, in order to list the Schools. And then it continues with the aggregate function. I am stucking here. The aggregate function is not so easy, because it refers to the other schools (For example, for School_01, the aggregate function is implemented for School_02 and School_03, not for School_01 as normally implemented)
I was thinking to perhaps use an OLAP function. But untill now, I havent found the right one to solve this problem.
Thanks for your help.
Regards,
Ratna