Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle: Analytic Function partitioned over nullable values

I DON't want to count NULL values. Because NULL should not be equal to NULL.

Look at this query result: link

WITH temp as (
SELECT 'A' as master , 1 Col from dual
UNION SELECT 'A' , 3  from dual
UNION SELECT 'B' , 1 from dual
UNION SELECT 'B' , 2 from dual
UNION SELECT 'C' , 1 from dual
UNION SELECT NULL , 1 from dual
UNION SELECT NULL , 2 from dual)
SELECT
   master,
   count(Col) over (partition by master)
FROM
  temp
like image 225
Revious Avatar asked Mar 09 '26 18:03

Revious


1 Answers

Alternatively, filter them out:

  1  WITH temp as (
  2  SELECT 'A' as master , 1 Col from dual
  3  UNION SELECT 'A' , 3  from dual
  4  UNION SELECT 'B' , 1 from dual
  5  UNION SELECT 'B' , 2 from dual
  6  UNION SELECT 'C' , 1 from dual
  7  UNION SELECT NULL , 1 from dual
  8  UNION SELECT NULL , 2 from dual)
  9  SELECT
 10     master,
 11     count(Col) over (partition by master)
 12  FROM
 13    temp
 14* WHERE master is not null
SQL> /

M COUNT(COL)OVER(PARTITIONBYMASTER)
- ---------------------------------
A                                 2
A                                 2
B                                 2
B                                 2
C                                 1
like image 132
Adam Musch Avatar answered Mar 11 '26 23:03

Adam Musch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!