title: BigQuery : is it possible to execute another query inside an UDF?
body: <p>I have a table that records a row for each unique user per day with some aggregated stats for that user on that day, and I need to produce a report that tells me for each day, the no. of unique users in the last 30 days including that day. </p>
  
  <p>eg. </p>
  
  <ul>
  <li>for Aug 31st, it'll count the unique users from Aug 2nd to Aug 31st</li>
  <li>for Aug 30th, it'll count the unique users from Aug 1st to Aug 30th</li>
  <li>and so on...</li>
  </ul>
  
  <p>I've looked at some related questions but they aren't quite what I need - if a user logs in on multiple days in the last 30 days he should be counted only once, so I can't just sum the DAU count for the last 30 days. </p>
  
  <p><a href="https://stackoverflow.com/questions/22415647/bigquery-sql-for-sliding-window-aggregate">Bigquery SQL for sliding window aggregate</a></p>
  
  <p><a href="https://stackoverflow.com/questions/27557919/bigquery-sql-for-28-day-sliding-window-aggregate-without-writing-28-lines-of-sq">BigQuery SQL for 28-day sliding window aggregate (without writing 28 lines of SQL)</a></p>
  
  <p>So far, my ideas are to either:</p>
  
  <ul>
  <li>write a simple script that'll execute a separate BigQuery for each of the relevant days</li>
  <li>write a BigQuery UDF that'll execute basically the same query for each day selected from another query</li>
  </ul>
  
  <p>but I've not found any examples on how to execute another BigQuery query inside an UDF, or if it's possible at all.</p>