oracle - reuse results from sql functions -
take @ beginning of query:
select sum(decode(regexp_count(tpdd.domain, 'thedomain.com'), 1, tpdd.size, 0, 0)) sizeclient, sum(decode(regexp_count(tpdd.domain, 'thedomain.com'), 1, 0, 0, tpdd.size)) sizethirdparty, ...
is there way reuse results of "regexp_count(tpdd.domain, 'thedomain.com')" function? should hope oracle server smart enough can't guarantee it, , besides, code better without repeated code.
you can use cte this:
domain_regex ( select tpdd.domain, regexp_count(tpdd.domain,'thedomain.com') regex_res ... ) select sum(decode(d.regex_res, 1, tpdd.size, 0, 0)) sizeclient, sum(decode(d.regex_res, 1, 0, 0, tpdd.size)) sizethirdparty, ... join domain_regex d on tpdd.domain = d.domain
Comments
Post a Comment