title: SQL UNION over all possible values for a column?
body: <p>Right now, what I am doing is </p>
  
  <pre><code>select t1.Team, t2.Total - SUM(t1.Diff) OVER (ORDER BY t1.DATE DESC ROWS UNBOUNDED PRECEDING) AS Amount
  from @trend t1 
  INNER JOIN @totalRecordsToday t2 on t1.Team = t2.Team
  WHERE t1.Team = 'Team1'
  GROUP BY t1.Team, t1.Date, t1.Diff, t2.Total, t1.NewlyAdded, t1.Resolved, t1.Diff
  UNION
  select t1.Team, t2.Total - SUM(t1.Diff) OVER (ORDER BY t1.DATE DESC ROWS UNBOUNDED PRECEDING) AS Amount
  from @trend t1 
  INNER JOIN @totalRecordsToday t2 on t1.Team = t2.Team
  WHERE t1.Team = 'Team2'
  GROUP BY t1.Team, t1.Date, t1.Diff, t2.Total, t1.NewlyAdded, t1.Resolved, t1.Diff
  </code></pre>
  
  <p>And so on, for each distinct t1.Team value. This is a hard-coded approach as I am doing a union for each value of t1.Team that I know. Is there a way for me to programmatically do a union over all distinct t1.Team values?</p>