0

It is a mystery to me with this text book example. We have simply:

Transaction_ID (primary key),   Client_ID,  Transaction_Amount, Month

1                   1       500         1   
2                   1       1000            1
3                   1       10          2
4                   2       11          2
5                   3       300         2
6                   3       10          2
...                 ...     ...         ...

I want to calculate in SQL the mean(Transaction_Amount), std(Transaction_Amount) and the some percentile(Transaction amount) grouped by Client_ID. But is seems, even given that percentile is a very similar calculation than the standard deviation, SQL cannot do it with a simple statement as:

SELECT
    mean(Transaction_Amount),
    std(Transaction_Amount),
    percentile(Transaction_Amount) 
FROM
    myTable
GROUP BY
    Client_ID, Month

Or can it?

It gets worse becuase I also need to Group By Month in addition to Client_ID.

Thanks a lot! Sven

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

1 Answers1

0

I'm sure Oracle can do the calculations you want. I just don't know what they are. You specify that you want something grouped by ClientId. Yet, your sample query has two keys in the GROUP BY.

Some functions that you want to look at are:

  • AVG()
  • STDDEV()
  • PERCENT_RANK()

Without sample data and desired results (or a very clear explanation of what you are trying to calculate), I can't put together a query.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786