obieeoracle-bi

BI Answers COUNT the number in cloumn?


Here is the data look like.

Name    P_ID    NUM
 A       P1      3
 A       P2      1
 B       P3      1
 B       P4      1
 C       P5      2
 D       P7      1

In BI Answers I want the result show like this:

Name    NUM_OF_1    NUM_OF_2    NUM_OF_3    SUM
 A         1           0           1         2
 B         2           0           0         2
 C         0           1           0         1
 D         1           0           0         1

The column NUM_OF_N is occurrences of a number in a 'name' group.


Solution

  • If you are looking for a SQL query then you can try the following pivot:

    SELECT Name,
           SUM(CASE WHEN NUM = 1 THEN 1 ELSE 0 END) AS NUM_OF_1,
           SUM(CASE WHEN NUM = 2 THEN 1 ELSE 0 END) AS NUM_OF_2,
           SUM(CASE WHEN NUM = 3 THEN 1 ELSE 0 END) AS NUM_OF_3,
           COUNT(*) AS "SUM"
    FROM yourTable
    GROUP BY Name