Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Count in SQL
*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