Day 4 of 5
⏱ ~60 minutes
Google Cloud in 5 Days — Day 4

BigQuery for Analytics

Load data into BigQuery, write SQL to analyze it, understand partitioning, and visualize results with Looker Studio.

BigQuery Basics

BigQuery is Google's serverless data warehouse. You pay per query (first 1TB/month free). It can analyze terabytes in seconds using standard SQL.

bq CLI
# Create a dataset
bq mk --dataset my_project:my_dataset

# Load a CSV file
bq load \
  --source_format=CSV \
  --autodetect \
  my_dataset.my_table \
  gs://my-bucket/data.csv

# Run a query
bq query --use_legacy_sql=false \
  'SELECT name, COUNT(*) as count FROM my_dataset.my_table GROUP BY name ORDER BY count DESC LIMIT 10'
SQL in BigQuery Console
-- BigQuery supports standard SQL
SELECT
  DATE(created_at) as day,
  COUNT(*) as events,
  SUM(revenue) as total_revenue,
  AVG(revenue) as avg_revenue
FROM `my_project.analytics.events`
WHERE created_at >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND status = 'completed'
GROUP BY day
ORDER BY day DESC

-- Window functions work
SELECT
  user_id,
  event_time,
  ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY event_time) as session_event
FROM `my_project.analytics.events`
💡
Partition your tables by date column when working with time-series data. Queries that filter by date then only scan the relevant partitions instead of the whole table — dramatically cheaper and faster: PARTITION BY DATE(created_at).
📝 Day 4 Exercise
Analyze a Public Dataset
  1. O
  2. p
  3. e
  4. n
  5. B
  6. i
  7. g
  8. Q
  9. u
  10. e
  11. r
  12. y
  13. i
  14. n
  15. t
  16. h
  17. e
  18. G
  19. C
  20. P
  21. c
  22. o
  23. n
  24. s
  25. o
  26. l
  27. e
  28. .
  29. Q
  30. u
  31. e
  32. r
  33. y
  34. a
  35. p
  36. u
  37. b
  38. l
  39. i
  40. c
  41. d
  42. a
  43. t
  44. a
  45. s
  46. e
  47. t
  48. (
  49. B
  50. i
  51. g
  52. Q
  53. u
  54. e
  55. r
  56. y
  57. h
  58. a
  59. s
  60. h
  61. u
  62. n
  63. d
  64. r
  65. e
  66. d
  67. s
  68. )
  69. .
  70. T
  71. r
  72. y
  73. :
  74. <
  75. c
  76. o
  77. d
  78. e
  79. >
  80. b
  81. i
  82. g
  83. q
  84. u
  85. e
  86. r
  87. y
  88. -
  89. p
  90. u
  91. b
  92. l
  93. i
  94. c
  95. -
  96. d
  97. a
  98. t
  99. a
  100. .
  101. g
  102. i
  103. t
  104. h
  105. u
  106. b
  107. _
  108. r
  109. e
  110. p
  111. o
  112. s
  113. .
  114. c
  115. o
  116. m
  117. m
  118. i
  119. t
  120. s
  121. <
  122. /
  123. c
  124. o
  125. d
  126. e
  127. >
  128. o
  129. r
  130. <
  131. c
  132. o
  133. d
  134. e
  135. >
  136. b
  137. i
  138. g
  139. q
  140. u
  141. e
  142. r
  143. y
  144. -
  145. p
  146. u
  147. b
  148. l
  149. i
  150. c
  151. -
  152. d
  153. a
  154. t
  155. a
  156. .
  157. u
  158. s
  159. a
  160. _
  161. n
  162. a
  163. m
  164. e
  165. s
  166. .
  167. u
  168. s
  169. a
  170. _
  171. 1
  172. 9
  173. 1
  174. 0
  175. _
  176. 2
  177. 0
  178. 1
  179. 3
  180. <
  181. /
  182. c
  183. o
  184. d
  185. e
  186. >
  187. .
  188. W
  189. r
  190. i
  191. t
  192. e
  193. 3
  194. q
  195. u
  196. e
  197. r
  198. i
  199. e
  200. s
  201. :
  202. c
  203. o
  204. u
  205. n
  206. t
  207. ,
  208. f
  209. i
  210. l
  211. t
  212. e
  213. r
  214. ,
  215. a
  216. n
  217. d
  218. a
  219. g
  220. g
  221. r
  222. e
  223. g
  224. a
  225. t
  226. e
  227. .

Day 4 Summary

  • BigQuery is serverless — no servers to manage. Pay per TB scanned (first 1TB/month free).
  • Standard SQL. Window functions, subqueries, CTEs, JOINs — it all works.
  • Partition by date for time-series data. Clustering further improves query performance.
  • Looker Studio connects directly to BigQuery for free visualization dashboards.
Finished this lesson?