title: How to use results of a sub-query in a super query?
body: <p>I am trying to find the average age in a scenario of multiple tables. The problem is that age is a derived attribute calculated from date of birth. Now I have written the following query which has the age of all the people that meet the condition. Now I want to find the average age of all of these but I am not sure how to use the results of the sub-query in the super-query.</p>
  
  <p>The query is:</p>
  
  <pre><code>Select  
      case
          when date(dob, '+' ||
              (strftime('%Y', 'now') - strftime('%Y', dob)) ||
              ' years') &lt;= date('now')
          then strftime('%Y', 'now') - strftime('%Y', dob)
          else strftime('%Y', 'now') - strftime('%Y', dob) - 1
      end
      as age
  from UserProfile where User_ID in
  (Select User_ID from UserProfile
  where User_ID IN
  (Select Channel_ID
  from Channels
  where Channel_Type = 'Public-Channel'
  group by Channel_ID
  HAVING (SUM(LENGTH(Video_IDs) - LENGTH(REPLACE(Video_IDs, ',', '')) + 1)) &gt; 4));
  </code></pre>
  
  <p>And the output is a one column list of all ages, can you tell me how to calculate the average age because that's the only thing I want to display.</p>