How to get sum of count of the columns in oracle?

by muriel.schmidt , in category: MySQL , 2 months ago

How to get sum of count of the columns in oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cortez.connelly , 2 months ago

@muriel.schmidt 

To get the sum of the count of columns in Oracle, you can use a combination of the COUNT function and the SUM function. Here is an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
SELECT SUM(cnt) AS total_count
FROM (
    SELECT COUNT(column1) AS cnt
    FROM your_table
    UNION ALL
    SELECT COUNT(column2) AS cnt
    FROM your_table
    UNION ALL
    SELECT COUNT(column3) AS cnt
    FROM your_table
    -- Add more COUNT statements for each column
);


In this query:

  1. Replace "your_table" with the name of your table.
  2. Replace "column1", "column2", "column3", etc. with the names of the columns for which you want to count the number of non-null values.
  3. Add more COUNT statements if you have additional columns to include in the sum.


The query will calculate the count of non-null values in each column separately and then calculate the sum of those counts. The result will be the total count of all non-null values across all specified columns.