oracle - SQL attribute variant within the same statement -



oracle - SQL attribute variant within the same statement -

having next statement gives me 4 columns (location,description,parent,count) depending on status:

select kincident.location, locations.description, lochierarchy.parent, count(kincident.incnum) kindicent, locations, lochierarchy kincident.location = locations.location , locations.location = lochierarchy.location , kincident.status = 'eccapr' grouping kincident.location, locations.description, lochierarchy.parent order parent;

however, i'd 5th column gives me count when kincident.status='fsapr' instead. how can specify status each count column takes?

you want conditional aggregation. should larn utilize explicit joins:

select k.location, l.description, h.parent, sum(case when k.status = 'eccapr' 1 else 0 end) cnt_eccapr, sum(case when k.status = 'fsapr' 1 else 0 end) cnt_fsapr kindicent k bring together locations l on k.location = l.location bring together lochierarchy h on l.location = h.location grouping k.location, l.description, h.parent order parent;

i introduced table aliases create queries easier write , read.

sql oracle

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -