× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

combining two multiple bigquery SELECT FROM statements

Marton
Jun 12, 2015
<p>You can count distinct users like this:</p> <pre><code>SELECT EXACT_COUNT_DISTINCT(userId) as buyers FROM (FLATTEN([table1], user_attribute)) WHERE event_value &gt; 0 AND event_parameters.Name = "SKU" </code></pre> <p>One way to join them is to add a static scalar value and use that for join:</p> <pre><code>SELECT buyers/total FROM ( SELECT EXACT_COUNT_DISTINCT(userId) AS buyers, 1 AS scalar, FROM (FLATTEN([table1], user_attribute)) WHERE event_value &gt; 0 AND event_parameters.Name = "SKU") a JOIN ( SELECT COUNT(userId) AS total, 1 AS scalar, FROM (FLATTEN([table1], user_attribute)) ) b ON a.scalar=b.scalar </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/30651161/combining%20two%20multiple%20bigquery%20SELECT%20FROM%20statements/30651823">Stack Overflow</a>.</p>
comments powered by Disqus