Note that there are some explanatory texts on larger screens.

plurals
  1. PONull value returned on Count Distinct (pl sql)
    primarykey
    data
    text
    <p>Preemptive apologies for the nonsensical table/column names on these queries. If you've ever worked with the DB backend of Remedy, you'll understand.</p> <p>I'm having a problem where a Count Distinct is returning a null value, when I suspect the actual value should be somewhere in the 20's (23, I believe). Below is a series of queries and their return values.</p> <pre><code>SELECT count(distinct t442.c1) FROM t442, t658, t631 WHERE t442.c1 = t658.c536870930 AND t442.c200000003 = 'Network' AND t442.c536871139 &lt; 2 AND t631.c536870913 = t442.c1 AND t658.c536870925 = 1 AND (t442.c7 = 6 OR t442.c7 = 5) AND t442.c536870954 &gt; 1141300800 AND (t442.c240000010 = 0) </code></pre> <p>Result = 497.</p> <p>Add table t649 and make sure it has records linked back to table t442:</p> <pre><code> SELECT COUNT (DISTINCT t442.c1) FROM t442, t658, t631, t649 WHERE t442.c1 = t658.c536870930 AND t442.c200000003 = 'Network' AND t442.c536871139 &lt; 2 AND t631.c536870913 = t442.c1 AND t658.c536870925 = 1 AND (t442.c7 = 6 OR t442.c7 = 5) AND t442.c536870954 &gt; 1141300800 AND (t442.c240000010 = 0) AND t442.c1 = t649.c536870914 </code></pre> <p>Result = 263.</p> <p>Filter out records in table t649 where column c536870939 &lt;= 1:</p> <pre><code>SELECT COUNT (DISTINCT t442.c1) FROM t442, t658, t631, t649 WHERE t442.c1 = t658.c536870930 AND t442.c200000003 = 'Network' AND t442.c536871139 &lt; 2 AND t631.c536870913 = t442.c1 AND t658.c536870925 = 1 AND (t442.c7 = 6 OR t442.c7 = 5) AND t442.c536870954 &gt; 1141300800 AND (t442.c240000010 = 0) AND t442.c1 = t649.c536870914 AND t649.c536870939 &gt; 1 </code></pre> <p>Result = 24.</p> <p>Filter on the HAVING statement:</p> <pre><code>SELECT COUNT (DISTINCT t442.c1) FROM t442, t658, t631, t649 WHERE t442.c1 = t658.c536870930 AND t442.c200000003 = 'Network' AND t442.c536871139 &lt; 2 AND t631.c536870913 = t442.c1 AND t658.c536870925 = 1 AND (t442.c7 = 6 OR t442.c7 = 5) AND t442.c536870954 &gt; 1141300800 AND (t442.c240000010 = 0) AND t442.c1 = t649.c536870914 AND t649.c536870939 &gt; 1 HAVING COUNT (DISTINCT t631.c536870922) = COUNT (DISTINCT t649.c536870931) </code></pre> <p>Result = null.</p> <p>If I run the following query, I can't see anything in the result list that would explain why I'm not getting any kind of return value. This is true even if I remove the DISTINCT from the SELECT. (I get 25 and 4265 rows of data back, respectively).</p> <pre><code>SELECT DISTINCT t442.c1, t631.c536870922, t649.c536870931 FROM t442, t658, t631, t649 WHERE t442.c1 = t658.c536870930 AND t442.c200000003 = 'Network' AND t442.c536871139 &lt; 2 AND t631.c536870913 = t442.c1 AND t658.c536870925 = 1 AND (t442.c7 = 6 OR t442.c7 = 5) AND t442.c536870954 &gt; 1141300800 AND (t442.c240000010 = 0) AND t442.c1 = t649.c536870914 AND t649.c536870939 &gt; 1 </code></pre> <p>I have several other places where I have the query set up exactly like the one that is returning the null value and it work perfectly fine--returning usable numbers that are the correct values. I have to assume that whatever is unique in this situation is related to data and not the actual query, but I'm not sure what to look for in the data to explain it. I haven't been able to find any null values in the raw data before aggregation. I don't know what else would cause this.</p> <p>Any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload