avatarNaina Chaturvedi

Summary

Day 8 of the 15 Days of Advanced SQL Series focuses on BigQuery basics, including SELECT, FROM, and WHERE clauses, as well as Date and Extract functions.

Abstract

The article is the eighth installment in a series dedicated to advanced SQL topics, specifically targeting BigQuery. It introduces readers to the foundational aspects of BigQuery, a serverless, scalable data warehouse on Google Cloud Platform. The author provides insights into using SQL in BigQuery, emphasizing the SELECT, FROM, and WHERE clauses for data retrieval and manipulation. Additionally, the article delves into the use of DATE and EXTRACT functions to handle dates effectively within BigQuery queries. The author also shares a GitHub repository with resources for further learning and announces the availability of Day 9's

Day 8 of 15 Days of Advanced SQL Series

Pic credits : dat.it

Welcome back peeps. Hope all’s well. Last two weeks have been crazy busy at work for me (plus I was traveling).

Day 1 : SQL Basics and Kick start of Advanced SQL Series

Day 2 : SQL Basics, Query Structure, Built In functions Conditions

Day 3 : Most Important Commands, Joins and Filters

Day 4 : Set Theory Operations, Stored Procedures and CASE statements in SQL

Day 5 : Wildcards, Aggregation and Sequences in SQL

Day 6 : Subqueries, Group by, order by and Having clauses in SQL and Analytical Functions

Day 7 : Window Functions, Grouping Sets and Constraints in SQL

Day 8 : BigQuery Basics, SELECT, FROM, WHERE and Date and Extract in BigQuery

Day 9 : Common Expression Table, UNNEST Clause, SQL vs NoSQL Databases

Day 10 : Triggers, Pivot and Cursors in SQL

Day 11 : Views, Indexes and Auto Increment in SQL

Day 12 : Query optimizations, Performance tuning in SQL

Day 13 : Introduction to MySQL, PostgreSQL and Mongo DB, Comparison between MySQL and PostgreSQL and Mongo DB, Introduction to SQL and NoSQL Databases

Day 14 : MySQL in Depth

Day 15 : PostgreSQL inDepth

Anyways, For Day 8 of the 15 days of Advanced SQL, we will cover —

BigQuery basics

SELECT, FROM and WHERE clauses in Bigquery

Date and Extract Clauses in Bigquery

Github for Advanced SQL that you can follow —

Projects Videos —

All the projects, data structures, SQL, algorithms, system design, Data Science and ML , Data Analytics, Data Engineering, , Implemented Data Science and ML projects, Implemented Data Engineering Projects, Implemented Deep Learning Projects, Implemented Machine Learning Ops Projects, Implemented Time Series Analysis and Forecasting Projects, Implemented Applied Machine Learning Projects, Implemented Tensorflow and Keras Projects, Implemented PyTorch Projects, Implemented Scikit Learn Projects, Implemented Big Data Projects, Implemented Cloud Machine Learning Projects, Implemented Neural Networks Projects, Implemented OpenCV Projects,Complete ML Research Papers Summarized, Implemented Data Analytics projects, Implemented Data Visualization Projects, Implemented Data Mining Projects, Implemented Natural Leaning Processing Projects, MLOps and Deep Learning, Applied Machine Learning with Projects Series, PyTorch with Projects Series, Tensorflow and Keras with Projects Series, Scikit Learn Series with Projects, Time Series Analysis and Forecasting with Projects Series, ML System Design Case Studies Series videos will be published on our youtube channel ( just launched).

Subscribe today!

System Design Case Studies — In Depth

Design Instagram

Design Messenger App

Design Twitter

Design URL Shortener

Design Dropbox

Design Youtube

Design API Rate Limiter

Design Web Crawler

Design Facebook’s Newsfeed

Design Yelp

Design Uber

Design Tinder

Design Tiktok

Design Whatsapp

Most Popular System Design Questions

Mega Compilation : Solved System Design Case studies

Complete Data Structures and Algorithm Series

Complexity Analysis

Backtracking

Sliding Window

Greedy Technique

Two pointer Technique

Arrays

Linked List

Strings

Stack

Queues

Hash Table/Hashing

Binary Search

1- D Dynamic Programming

Divide and Conquer Technique

Recursion

Github —

Let’s get started with Day 8.

  • In BigQuery, the SELECT, FROM, and WHERE clauses work similarly to how they work in standard SQL.
  • The SELECT clause is used to specify the columns that you want to retrieve from the table. You can use the * wildcard character to select all columns.
  • The FROM clause is used to specify the table or tables from which you want to retrieve data. You can also use subqueries and join multiple tables together in the FROM clause.
  • The WHERE clause is used to filter the data retrieved by the query by specifying the conditions that must be met for a row to be included in the result set.
SELECT *
FROM your_table
WHERE DATE(date_column) = '2023-05-21'
  • In BigQuery, you can use the DATE and EXTRACT functions to work with dates in your queries.
  • The EXTRACT function allows you to extract parts of a date, such as the year, month, or day.
  • BigQuery also supports a number of other date and time functions such as DATE_TRUNC, DATE_DIFF and TIMESTAMP_DIFF which can be used to perform operations on date and time fields.
SELECT EXTRACT(YEAR FROM date_column) AS year,
       EXTRACT(MONTH FROM date_column) AS month,
       EXTRACT(DAY FROM date_column) AS day
FROM your_table

In summary, the SELECT, FROM and WHERE clauses in BigQuery are used to specify the columns, tables, and conditions for retrieving data from a BigQuery table. Additionally, the DATE and EXTRACT functions can be used to work with dates and extract parts of a date in BigQuery.

BigQuery basics

Pic credits : cx

BigQuery is a Serverless, highly scalable, and cost-effective multi-cloud data warehouse designed for business agility and is integrated on Google Cloud Platform. If you are a developer who works with huge amounts of data, you can use Google Cloud Platform to query petabytes of data at fast speeds. In this post you will learn how to use different clauses of Standard SQL to analyze your data on Google Cloud Platform.

To get started signup : https://cloud.google.com/

SELECT, FROM and WHERE clauses in Bigquery

In order to retrieve or pull all the columns and rows we use * with the SELECT statement. To pull the selective columns we define the column names with the SELECT Statement. FROM statement is used to specify the table from which you would like to retrieve the data. WHERE is used to filter the rows that meet certain condition or criteria.

Format to use SELECT, FROM and Where :

SELECT column_names

FROM table_name

WHERE condition

WHERE clause is used with SELECT, UPDATE and DELETE statement

Implementation —

SELECT *
FROM table_name
WHERE condition

Date and Extract Clauses in Bigquery

Alias is used to give a shorthand name for a table or column. Whenever you create complex queries, Alias can help you to improve the readability of your query.

Format to use Alias

SELECT column_name AS Alias-name

FROM table alias_name

WHERE condition

BigQuery has rich DATETIME Functions.

In order to know the current date and time, use the CURRENT_DATETIME function which will return the current time as a DATETIME object.

Format —

CURRENT_DATETIME([timezone])

Implementation —

SELECT CURRENT_DATETIME() AS current_datetime

Since the DATETIME format is in the form of DATETIME(year, month, day, hour, minute, second). In order to Extract the year or month or day or hour or minute, second etc you can use the EXTRACT clause which returns a value that corresponds to the specified part from a supplied expression_datetime.

Format —

EXTRACT(part FROM expression_datetime)

  • DAY: Returns values in the range [1,7] with Sunday as the first day of the week.
  • YEAR returns the year.
  • WEEK: Returns the week number of the date in the range [0, 53]. Weeks begin with Sunday, and dates prior to the first Sunday of the year are in week 0.
  • MONTH
  • QUARTER: Returns values in the range [1,4].

Implementation —

SELECT EXTRACT(YEAR FROM your_datetime_column) AS year,
       EXTRACT(MONTH FROM your_datetime_column) AS month,
       EXTRACT(DAY FROM your_datetime_column) AS day,
       EXTRACT(HOUR FROM your_datetime_column) AS hour,
       EXTRACT(MINUTE FROM your_datetime_column) AS minute,
       EXTRACT(SECOND FROM your_datetime_column) AS second
FROM your_table

That’s it for now.

Find Day 9 Below :

Let me know if you have questions in the comment section below. Subscribe/ Follow, Like/Clap as it would encourage me to write more in my free time

Stay Tuned!!

Read More —

11 most important System Design Base Concepts

1. System design basics

2. Horizontal and vertical scaling

3. Load balancing and Message queues

4. High level design and low level design, Consistent Hashing, Monolithic and Microservices architecture

5. Caching, Indexing, Proxies

6. Networking, How Browsers work, Content Network Delivery ( CDN)

7. Database Sharding, CAP Theorem, Database schema Design

8. Concurrency, API, Components + OOP + Abstraction

9. Estimation and Planning, Performance

10. Map Reduce, Patterns and Microservices

11. SQL vs NoSQL and Cloud

12. Most Popular System Design Questions

13. System Design Template — How to solve any System Design Question

14. Quick RoundUp : Solved System Design Case Studies

Some of the other best Series —

60 days of Data Science and ML Series with projects

30 Days of Natural Language Processing ( NLP) Series

30 days of Machine Learning Ops

30 days of Data Structures and Algorithms and System Design Simplified

60 Days of Deep Learning with Projects Series

30 days of Data Engineering with projects Series

Data Science and Machine Learning Research ( papers) Simplified **

100 days : Your Data Science and Machine Learning Degree Series with projects

23 Data Science Techniques You Should Know

Tech Interview Series — Curated List of coding questions

Complete System Design with most popular Questions Series

Complete Data Visualization and Pre-processing Series with projects

Complete Python Series with Projects

Complete Advanced Python Series with Projects

Kaggle Best Notebooks that will teach you the most

Complete Developers Guide to Git

Exceptional Github Repos — Part 1

Exceptional Github Repos — Part 2

All the Data Science and Machine Learning Resources

210 Machine Learning Projects

Tech Newsletter —

If you are interested, you can join my newsletter through which I send tech interview tips, techniques, patterns, hacks — Software Development, ML, Data Science, Startups and Technology projects to more than 30K readers. You can subscribe to Tech Brew :

For Python Projects —

For complete 60 days of Data Science and ML : Day 1 — Day 60 : Quick Recap of 60 days of Data Science and ML

Follow for more updates. Stay tuned and keep coding!

For other projects, tune to —

Build Machine Learning Pipelines( With Code)

Recurrent Neural Network with Keras

Clustering Geolocation Data in Python using DBSCAN and K-Means

Facial Expression Recognition using Keras

Hyperparameter Tuning with Keras Tuner

Custom Layers in Keras

Programming
Tech
Software Development
Data Science
Machine Learning
Recommended from ReadMedium