Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Count in SQL

Count in SQL

From: Marco Shaw <marco_at_Znbnet.nb.ca>
Date: Thu, 28 Jul 2005 14:10:19 GMT
Message-ID: <fH5Ge.66378$Ph4.2082174@ursa-nb00s0.nbnet.nb.ca>


*SQL newbie alert*

I have 2 tables, and I need to write some SQL to output counts of various entries.

I've managed to kind of figure out how to proceed when only one thing needs to be counted:

select

        to_char(count(*)) cnt, node.node_name from

        opc_node_names node,
        opc_act_messages act
where
        act.node_id = node.node_id and
        act.severity = 1
group by
        node.node_name
order by
        count(*) DESC, node.node_name;

That about outputs simply something like:

300 server_1
400 server_2
etc.

Now I need to also have a number similar to above, but also take into account totals in other columns of the tables.

For example, above I just check a table for all the instances of server_name where severity=1, but I'll also need to count all the instances of server_name where severity=1 and column X or column Y have a value set (not null). The output might look like:

server messages column Y column X
-------- ---------- ---------- ---------- server_1 300 200 100

Note that X+Y=300 like the messages value.

So how can I setup different 'counts' properly?

Very hard to explain!

Marco Received on Thu Jul 28 2005 - 09:10:19 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US