Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: More SQL counting questions...
This may not be the slickest solution but it works for the test data
given. I just broke the problem into queries for part of the data and
(outer) joined them. If there are more than 2 types of messages you
will probably need to modify the solution since I derived the major
error count as total count minus critical. But writing the query to
sum 0 or 1 for critical and major in one query is easy with
case/decode.
drop table A;
create table A (
servername varchar2(10),
severity number,
log number, notif number); insert into A values ('A',32,0,0); insert into A values ('A',32,1,0);
UT1 > select drv.servername, drv.severity,
2 nvl(sev.critical,0) critical, 3 nvl(drv.severity,0) - nvl(sev.critical,0) as major, 4 drv.log, 5 drv.notif
SERVERNAME SEVERITY CRITICAL MAJOR LOG NOTIF ---------- ---------- ---------- ---------- ---------- ----------
A 3 2 1 2 1 B 1 0 1 0 0
HTH -- Mark D Powell -- Received on Fri Aug 05 2005 - 10:36:02 CDT