Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CreateSQLQuery()
- Dim SQLQuery As String
- SQLQuery = _
- "SELECT t1.[Genre], t.[Number of Films], t1.[Total Run Time], t1.[Average Run Time] " & _
- "FROM " & _
- "(SELECT " & _
- "0 AS [SortColumn] " & _
- ",t.[Genre] " & _
- ",Sum(t.[Number of Films]) AS [Number of Films] " & _
- ",Sum(t.[Total Run Time]) AS [Total Run Time] " & _
- ",Sum(t.[Total Run Time]) / Sum(t.[Number of Films]) AS [Average Run Time] " & _
- "FROM " & _
- "(SELECT [Genre], [Number of Films], [Total Run Time], 2010 AS [Year] FROM [Genres2010$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2011 FROM [Genres2011$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2012 FROM [Genres2012$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2013 FROM [Genres2013$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2014 FROM [Genres2014$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2015 FROM [Genres2015$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2016 FROM [Genres2016$]) AS t " & _
- "GROUP BY " & _
- "t.[Genre] "
- SQLQuery = SQLQuery & _
- "UNION ALL SELECT " & _
- "1 " & _
- ",'SUMMARY' " & _
- ",Sum(t.[Number of Films]) AS [Number of Films] " & _
- ",Sum(t.[Total Run Time]) AS [Total Run Time] " & _
- ",Sum(t.[Total Run Time]) / Sum(t.[Number of Films]) AS [Average Run Time] " & _
- "FROM " & _
- "(SELECT [Genre], [Number of Films], [Total Run Time], 2010 AS [Year] FROM [Genres2010$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2011 FROM [Genres2011$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2012 FROM [Genres2012$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2013 FROM [Genres2013$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2014 FROM [Genres2014$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2015 FROM [Genres2015$] " & _
- "UNION ALL SELECT [Genre], [Number of Films], [Total Run Time], 2016 FROM [Genres2016$]) AS t) AS t1 " & _
- "ORDER BY " & _
- "t1.[SortColumn] ASC, t1.[Number of Films] DESC "
- GetQueryResults SQLQuery
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement