Query that count only the column null lines

create table test
(a varchar2 (10))
b varchar2 (10),
c varchar2 (10),
d varchar2 (10),
e varchar2 (10));


SQL > DESC TEST
Name Null? Type
------------------------------- -------- ----
A VARCHAR2 (10)
B VARCHAR2 (10)
C VARCHAR2 (10)
D VARCHAR2 (10)
E VARCHAR2 (10)

SQL > SELECT * FROM TEST;

A B C D E
---------- ---------- ---------- ---------- ----------
A1 - A3 A4-
B1 - B3, B4-
C1 - C3 C4-
D1 - D4 D5
-E2 - E4 E5


I want an application that only count the rows of the column as null

A B C D E
--- ---- ----- ------ -------
1 4 2 0 3

Published by: Nilesh hole, Pune, India, on August 28, 2009 12:30
select SUM(case when a is null then 1 else 0 end)
      ,SUM(case when b is null then 1 else 0 end)
      ,SUM(case when c is null then 1 else 0 end)
      ,SUM(case when d is null then 1 else 0 end)
      ,SUM(case when e is null then 1 else 0 end)
from TEST
/

Published by: Toon Koppelaars August 28, 2009 09:07

Tags: Database

Similar Questions

  • Need help to write a MySQL query that returns only the peer matching records

    Because I don't know how to explain it easily, I use the table below as an example.

    I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.

    Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.

    How can I create a query that will do it?


    ID | col1 | col2
    --------------------
    1. ABC | DEF
    2. DEF | ABC
    3. ABC | IGS
    4. DEF | IGS
    5. IGS | DEF


    * Please let me know if you have no idea of what I'm trying to explain.

    I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.

    SELECT a.col1,
    a.col2
    FROM table_name AS a
    LEFT OUTER
    Table_name JOIN b
    ON b.col1 = a.col2
    AND a.col1 = b.col2
    WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.

  • A query to extract only the non-null columns.

    Hello

    I have a table with:

    COLA, COLB TEACHERS COLD COLE

    AA BB < null > < null > JJ

    < Null > < null > CC < null > EE


    I need a query that retrieves only 1 rows like this:

    COLA, COLB TEACHERS COLD COLE

    AA BB CC DD EE


    My version of the database is 11.2


    Thnak you

    odd design but in this case, you could go with MAX (or MIN)

    HTH

  • Return only the columns with different values.

    Hi all

    I am trying to solve a seemingly trivial problem but can't seem to get any clear answer anywhere in any forum. Consider a single table with 5 columns and only two lines:
    row_id           first_name         last_name        age            gender
    1                    John                  doe               27             M
    1                    Jane                  doe               27              F  
    Assume that there is no primary key or any other constraint. Also assume that there are only and only two lines of this table. So I need basically a query that, overall above lines, would return first name and sex, because they are only different columns in two lines, as well as their values. Even if I can get sort of column names that are different and that would be enough that I can easily access the values later. It is also important to remember that I may not know the names of the columns in the columns, so basically, somehow, I use user_tab_columns in the process.

    Any help appreciated.

    Published by: 894302 on May 1, 2013 10:35

    Hello

    894302 wrote:
    The exact release could be just a varchar variable that lists all the columns that have different values with each column name separated by commas. We'll call the query you want as a QUERY. So, if I do something like

    Select the REQUEST of double; Output should be: 'first_name, equality of the sexes. Is this possible?

    In this case:

    SELECT     RTRIM ( DECODE (a.row_id,     b.row_id,     NULL, 'row_id,')     ||
                    DECODE (a.first_name, b.first_name, NULL, 'first_name,') ||
              DECODE (a.last_name,  b.last_name,  NULL, 'last_name,')  ||
              DECODE (a.age,        b.age,          NULL, 'age,')      ||
              DECODE (a.gender,     b.gender,     NULL, 'gender,')
               , ','
               )          AS different_columns
    FROM     rhit_table_x  a
    JOIN     rhit_table_x  b  ON  a.ROWID     < b.ROWID
    ;
    

    Output:

    DIFFERENT_COLUMNS
    ---------------------------------------
    first_name,gender
    

    This assumes that you have really a table, then you can use ROWID to distinguish the lines, since there is no primary key.
    If this isn't the case, you first assign ROW_NUMBER in a subquery.

  • PL/SQL Query return function, adding the column links

    Hi all

    I'm working on a SQL report with the area type = function from PL/SQL Query to return
    All columns are generated dynamically based on my mapping table and a column of ID.
    So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
    So not only the columns are dynamic, but the order of the columns varies also.
    But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.

    I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
    My pl/sql block is something like that...
    v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, ';  // g=a
    v_cols := 'contains all columns from the mapping table based on a ID(hidden item)';
    v_from := 'FROM table';
    v_where := 'where condition is put in here';
    v_query := v_select||v_from||v_where;
    return v_query;
    Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.

    I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
    How can I go to a column value to the function?



    Thank you
    Dippy

    This should work if all goes well:

    v_select := q'[ SELECT '' as chart, ]';
    

    Published by: Dimitri Gielis on May 20, 2010 20:10

  • Count only the iterations of duplicates? [SOLVED]

    Using Oracle 9i 9.2.0.6.0.

    This could be something simple that I am on, there are plenty of ways to find and count duplicates but I'm looking for a way to count only the number of iterations of a duplicate, it is and then group them if possible.

    For example, suppose that you have
    store   customer   product    date
      1          John          A         2008/05/01
    
      1          John          A         2008/05/01
    
    
      1          John          B         2008/05/01
    
    
      2          Bob           C         2008/05/01
    
    
      2          Bob           C         2008/05/01
    
    
      3          Mary          D         2008/05/01
    
    
      3          Mary          D         2008/05/01
    
    
      3          Mary          D         2008/05/01
    
    
      3          Joe            F         2008/05/01
    So I don't want to go back to the following:
    Store    Duplicates
      1               1
      2               1
      3               2
    I want to only count how many duplicates beyond the first row for each store, where a duplicate has the same store, the customer and the product. Then
    1 John A 2 Bob C, had one double, and Mary has 2.

    I've tried so far to use analytical functions to subtract the first value of each partition before doing a count or make a number from each partition but niether seems to work by a group of store.

    Published by: a little rabbit on September 18, 2008 13:03

    You can find the number for each group and subtract one, as follows.

    SQL> create table t ( store int, customer varchar2(10), product varchar2(1), d_ate date );
    
    Table created.
    
    SQL>
    SQL> insert all
      2     into t values ( 1, 'John', 'A', date '2008-05-01' )
      3     into t values ( 1, 'John', 'A', date '2008-05-01' )
      4     into t values ( 1, 'John', 'B', date '2008-05-01' )
      5     into t values ( 2, 'Bob',  'C', date '2008-05-01' )
      6     into t values ( 2, 'Bob',  'C', date '2008-05-01' )
      7     into t values ( 3, 'Mary', 'D', date '2008-05-01' )
      8     into t values ( 3, 'Mary', 'D', date '2008-05-01' )
      9     into t values ( 3, 'Mary', 'D', date '2008-05-01' )
     10     into t values ( 3, 'Joe',  'F', date '2008-05-01' )
     11  select null
     12  from   dual;
    
    9 rows created.
    
    SQL>
    SQL> select distinct
      2         store
      3  ,      cnt - 1 as duplicates
      4  from  (
      5         select store
      6         ,      customer
      7         ,      product
      8         ,      d_ate
      9         ,      count(*) over (partition by store, customer, product) as cnt
     10         from   t
     11        )
     12  where  cnt - 1 > 0;
    
         STORE DUPLICATES
    ---------- ----------
             2          1
             1          1
             3          2
    

    Concerning

  • How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    I have only:
    D: / images (where are necessary + not need files)
    -a list with only the necessary files
    -a list with new names for the files needed
    Thank you.

    Hi Pustiu,

    Thanks for posting in the Microsoft Community.

    You want to know how to select the files in a folder using a list with the files you want and after that rename only the files using another list with desired new names.

    I would have you post your query in the TechNet forums because it caters to an audience of it professionals.

    Your query will be better addressed there.

    Check out the link-

    http://social.technet.Microsoft.com/forums/en-us/w7itprogeneral/threads

    We know if you need help. We will be happy to help you. We, at tender Microsoft to excellence.

    Thank you.

  • We display only the columns required dynamically?

    Hi all

    I have a scenario where I have 30 columns in the rtf model. All columns will never be displayed, only a privileged few will be available for display. The output file is so see the empty columns. Now, I want to display only the columns that contain data.

    FYI - can't know what columns are made up of data until we run the report.

    Any advice.


    Thanks in advance.

    Malenfant.

    Hello

    You can use the following text:

    Column heading:
    My label

    The data in the column:
    My data

    The @column will tell XMLP wheater or not that column should be indicated.

    I hope this helps you.

    Kenneth BR

  • I want to place a menu bar that shows only the pages on the second level. How to do?

    I want to place a menu bar that shows only the pages on the second level. How to do?

    You must manually create the menu (new menu set to "Manual"). There is no way to automatically create the secondary menu.

  • How to create the map that updates only the changed lines

    Hello

    I have a map that made a merger (update/insert) in a table. The problem is that it will always update all rows in this table. I want to update only the changed lines.

    Some dummy code that shows what I want to do.
    Current situation (all lines updated):

    FUSION
    IN
    Table 1-t1
    USING
    (select key_column, Column1, Column2 from table2) t2
    ON)
    T1.key_column = t2.key_kolumn
    )

    WHEN MATCHED THEN
    UPDATE
    SET
    T1. Column1 = t2.column1
    T1. Column2 = t2.column2
    WHEN NOT MATCHED THEN
    INSERT
    (t1.key_column, t1.column1, t1.column2)
    VALUES
    (t2.key_column, t2.column1, t2.column2);

    What I'm trying to get (only changed the lines updated):
    FUSION
    IN
    Table 1-t1
    USING
    (select key_column, Column1, Column2 from table2) t2
    ON)
    T1.key_column = t2.key_kolumn
    )

    WHEN MATCHED THEN
    UPDATE
    SET
    T1. Column1 = t2.column1
    T1. Column2 = t2.column2
    * WHERE
    T1. Column1! = t2.column1
    or t1.column2! = t2.column2*
    WHEN NOT MATCHED THEN
    INSERT
    (t1.key_column, t1.column1, t1.column2)
    VALUES
    (t2.key_column, t2.column1, t2.column2);

    WHERE in WHEN MATCHED t clause is that I'm not able to create via OWB in the mapping. How is that possible?
    I tried to look for the solution here and google without success

    Thank you!

    Hello

    you left outer join table2, with table1. Then use a filter to determine which rows in which an attribute has changed or no towing in table1 where found.
    To compare attributes use expression with nvl to properly handle nulls: nvl(table2.my_attribute,'#')! = nvl(table1.my_attribute,'#')

    Kind regards
    Carsten.

  • Improve a simple select query that uses all the lines.

    Hi all

    Excuse me if the question is too dumb. Here is my code
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    
    Elapsed: 00:00:00.07
    SQL> show parameter optim
    
    NAME                                 TYPE        VALUE
    ------------------------------------ ----------- ------------------------------
    object_cache_optimal_size            integer     102400
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.1
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    plsql_optimize_level                 integer     2
    
    SQL> explain plan for select SUM(decode(transaction_type,'D',txn_amount,0)) payments_reversals,
      2          SUM(decode(transaction_type,'C',txn_amount,0)) payments,primary_card_no,statement_date
      3             from credit_card_pymt_dtls  group by primary_card_no,statement_date;
    
    Explained.
    
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    -----------------------------------------------------------------------------------------------------------------------
    -----------------------------------
    Plan hash value: 2801218574
    
    ----------------------------------------------------------------------------------------------------
    | Id  | Operation          | Name                  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |                       |  1912K|    56M|       | 21466   (3)| 00:04:18 |
    |   1 |  SORT GROUP BY     |                       |  1912K|    56M|   161M| 21466   (3)| 00:04:18 |
    |   2 |   TABLE ACCESS FULL| CREDIT_CARD_PYMT_DTLS |  1912K|    56M|       |  4863   (3)| 00:00:59 |
    ----------------------------------------------------------------------------------------------------
    
    9 rows selected.
    
    SQL> select index_name,index_type
      2  from all_indexes
      3  where table_name = 'CREDIT_CARD_PYMT_DTLS';
    
    INDEX_NAME                     INDEX_TYPE
    ------------------------------ --------------------
    INDX_TRANTYPE                  BITMAP
    INDX_PCARD                     NORMAL
    INDX_PSTATEMENT_DATE           NORMAL
    The query uses all records in the CREDIT_CARD_PYMT_DTLS table. Transaction type will be either 'C' or '.

    CREDIT_CARD_PYMT_DTLS has 2 million lines and the qury will display 1.5 million lines. Table statisticas are up to date.

    The query takes now almost 5 minutes. Y thaere a way to reduce the time?

    Our DB server has 8 processors and 8 GB of memory. Is it authentic?

    Thanks in advance.

    Published by: user11115924 on April 29, 2009 02:43
    All columns used in the query are already indexed. (Of course, not only for this query.)

    I should not get too hung up the full Table Scan necessarily - Oracle makes a decision, and even with your new index, he still thinks it is the most effective way to recover the data.

    Did you collect statistics on this new index?

    You have created the index with:

    TO_CHAR("STATEMENT_DATE",'MON-RRRR')
    

    Yet, you seem to be just by selecting statement_date in your query: Oracle cannot use the index (according to functions) in this case!

    If you have only a small number of columns in this table, you can consider an Table of Index organized (ITO), then the table itself is a clue.

    I'd be more inclined to optimize the complete analysis of the table and the creation of other clues, I would say, have you tried the PARALLEL tip?

  • ALTER TABLE with the column NULL time consuming

    Hello

    I have a table with nearly 2 million documents (about 10 GB size table) when I perform the following change statement its run fast

    ALTER TABLE tbl_1 ADD (DEFAULT col_4 NUMBER 100 NOT NULL);

    but when I do not give the NOT NULL in the alter its taking a long time to complete this i.e tbl_1 of ALTER TABLE ADD (NUMBER col_4 by DEFAULT 100); once I do the column as NOT NULL.

    Can someone explain why is it happening like that regarding the execution point.

    Thanks in advance.

    I can reproduce the effect in 11.2.0.1 - but not in 12.1.0.1.

    drop table tbl_1;

    create table tbl_1

    as

    Select rownum id

    , lpad ('* ', 50,' *') padding

    of the double

    connect by level<=>

    ALTER TABLE tbl_1 ADD (NUMBER col_4 by DEFAULT 100);

    --> slow in 11.2.0.1; fast 12.1.0.1

    ALTER TABLE tbl_1 ADD (DEFAULT col_4 NUMBER 100 NOT NULL);

    --> Quick 11.2.0.1 and 12.1.0.1

    A SQL trace for two operations (11g) shows that the altar slow (without the constraint explicit non-null) made explicit (and tedious) update of any row in the table:

    Update 'TBL_1"set"COL_4"= 100

    call the query of disc elapsed to cpu count current lines

    ------- ------  -------- ---------- ---------- ---------- ----------  ----------

    Parse        1      0.00       0.02          0          1          0           0

    Run 1 11,63 33.56 8336 1016125 2053531 1000000

    Fetch        0      0.00       0.00          0          0          0           0

    ------- ------  -------- ---------- ---------- ---------- ----------  ----------

    Total 2 11,63 33,58 8336 1016126 2053531 1000000

    The other trace file does not contain the explicit Update. I guess in the optimized case that oracle stores somewhere that col_4 has the value 100 and updates only the line of the block after completing DML operations. But that's just a guess.

  • Separate the values in the columns in lines

    Hello
    Here is my requirement
    create table test_test2 (deptno number ,enos varchar2(30))
    
    insert into test_test2 values (10,'101,102,103') 
    insert into test_test2 values (20,'104,105,107') 
    insert into test_test2 values (30,'106')
    
    Desired output
    
    deptno          enos
    10           101
    10          102
    10          103
    20          104
    20          105
    20           107
    30          106
    How can I achieve the above format.

    Thank you

    Hello

    Smile says:
    ... I tried your query, but get invalid data type error. I can't solve it. My version of oracle's 10g

    My apologies. Apparently, odcinumberlist does not work as I thought, he did it in Oracle 10. I tried the query I posted earlier in Oracle 11.1, but in 10.1.0.2.0 I «...» ORA-00904. invalid identifier"error, as you do.

    Even I tried the other ways in the link you provided I get the output as

    10  1
    10  0
    10 1
    10 ,
    ---
    

    OP in the thread else wanted each character on a separate line.
    You want each substring , separated by commas, on a separate line, so the technique of iterating over the chain and get a number N will be the same as in other this thread, but, once you have found a number N, how to generate the N - th line will be different.

    The changes I need to make...

    I just tested this in Oracle 10.1:

    WITH     got_part_cnt     AS
    (
         SELECT     deptno
         ,     enos
         ,     1 + LENGTH (enos)
                - LENGTH (REPLACE (enos, ','))     AS part_cnt
         FROM    test_test2
    )
    ,     cntr          AS
    (
         SELECT     LEVEL     AS n
         FROM     (
                  SELECT  MAX (part_cnt)     AS max_part_cnt
                  FROM    got_part_cnt
              )
         CONNECT BY     LEVEL     <= max_part_cnt
    )
    SELECT       p.deptno
    ,       REGEXP_SUBSTR ( p.enos
                     , '[^,]+'
                   , 1
                   , c.n
                   )     AS eno
    FROM       got_part_cnt  p
    JOIN       cntr          c  ON     c.n     <= p.part_cnt
    ORDER BY  p.deptno
    ,            c.n
    ;
    

    This assumes that your column enos is not missing elements, such as 901, 904', ot, if so, you want to treat commas repeated like a comma. If you have data like this, and you want to be the 4th point, 904 not the 2nd, then the apprioach even basic will work, but the details are a little more complicated.

  • Refine a query to display only the entries for the current week

    Hello.

    Anyone know how to change a query to display only those records that have dates of the current week? Records have a start date and an end date, so the query should recognize that the entry may be valid for more than one week?

    Kind regards

    swelch

    Hi Steve,.

    I just created a dataset that contained the periods before, during and after the current week - on the assumption that if any day of a range (start/end) falls within the current week so it is included.

    In my example this is 'today', June 25, 2011, and a week is defined as Sun - Sat. So my week of 'course' is u 19 June 2011 / I June 25, 2011.

    A line any with a start date before or during my 'current' week and an end date that is after or during my "current" week, i.e. no matter what date in its range included in the 'in progress' week will appear.

    See you soon,.
    Rob

  • does not scan the whole page, only the column

    My All-in-one HP Officejet Pro L7580 scanner does not scan the entire page.

    Regardless of where to send... Word, Mail, photos... all I get is about 3 inches of column of the entire page.

    What can I do to remedy this?

    IF the copy works perfectly. Try to open the HP Solution Center and find the settings > scan settings > scan document or scan picture settings.

    Search for advance settings or more and are looking for an option on the digitization of multiple files or just the entire page or something to that effect. The software may have missed in the analysis just a part of it. You can check the settings where you can have a preview of the scanned document and find the broken line around the scanned image, you need to move, it will scan what's inside the broken line.

Maybe you are looking for

  • Help/Explorer Windows and support issues

    Since a week ago whenever I try to open Windows Explorer to view the files and documents in my document folders, windows Explorer closes itself.At first, it all started when I tried to open the images and videos, that I saved on a new 500 GB extended

  • Definition of the typedef for a cluster

    I use a search tool IMAQ Edge. It has descriptor KING connected to IMAQ Edge search tool. I need a single value in the descriptor of KING are variable. How can I do? First idea: build your own return on investment for basis descriptors. I tried but s

  • Computer laptop Windows 7 can see the desktop of Windows XP, but cannot ping or you connect

    I've seen hundreds of threads describing problems similar to mine, but none of the suggested fixes worked in my case so I'm starting a new thread.  I bought a new laptop with Windows 7 Home Edition.  My setup before the new laptop was as follows: Cab

  • Windows 7 Pro will not restart if printer on.

    Hello When you click Restart, Windows 7 Pro will not reboot with a printer hp (L7680 or C309a) turned on.  The screen remains right on "Starting Windows".  Windows continues to load after that whatever printer is turned on. This problem just started.

  • 3522 cartridge transport will not "open".

    Problem with the initial installation of ink in my printer 3522nd.  Impossible to activate the ink cartridge transport to move left "open" position.  Cart remains on the far right and is inaccessible.  Displays "ink cartridge problem, one or more car