0% found this document useful (0 votes)
38 views

Beginners Guide To SQL

Uploaded by

muleva17vinod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Beginners Guide To SQL

Uploaded by

muleva17vinod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

SQL Queries Used

1. GROUP BY & ORDER BY


SELECT
language,
title,
SUM(views) AS views
FROM
`bigquery-samples.wikipedia_benchmark.Wiki10B`
WHERE
title LIKE '%Google%'
GROUP BY
language,
title
ORDER BY
views DESC;

2. LENGTH
SELECT
country
FROM
my-first-project-418418.customer_data.customer_address
WHERE
LENGTH(country) > 2

3. Filter Using WHERE


UPDATE
my-first-project-418418.cars.car_info
SET
num_of_doors = "four"
WHERE
make = "dodge"
AND fuel_type = "gas"
AND body_style = "sedan";

4. Update Query
UPDATE
my-first-project-418418.cars.car_info
SET
price = 5118
WHERE
price = 0
5. CASTE

SELECT
CAST(purchase_price AS float64)
#purchase_price
FROM
my-first-project-418418.customer_data.customer_purchase
ORDER BY
CAST(purchase_price AS float64) DESC

6. FILTER Using Between

SELECT
CAST (date AS date) AS date_needed,
purchase_price
FROM
my-first-project-418418.customer_data.customer_purchase
WHERE
date BETWEEN '2020-12-01' AND '2020-12-31'
MOVIE DATESET SQL COMMANDS

7. Sort data by one column


SELECT *
FROM projectID.movie_data.movies
ORDER BY Release_date;

8. Sort data in descending order


SELECT *
FROM projectID.movie_data.movies
ORDER BY Release_Date DESC;

9. Filter and sort data in descending order


SELECT *
FROM projectID.movie_data.movies
WHERE Genre = "Comedy"
ORDER BY Release_Date DESC;

10. Filter on two conditions, then sort data in descending order


SELECT *
FROM projectID.movie_data.movies
WHERE Genre = "Comedy"
AND Revenue > 300000000
ORDER BY Release_Date DESC;

HANDON TASK

11. LOAD THE CBC DATASET


SELECT
*
FROM
bigquery-public-data.sdoh_cdc_wonder_natality.county_natality
LIMIT
1000
12. ORDER BY Births
SELECT
*
FROM
bigquery-public-data.sdoh_cdc_wonder_natality.county_natality
ORDER BY
Births
LIMIT
1000

13. ORDER BY Births in Descending order


SELECT
*
FROM
bigquery-public-data.sdoh_cdc_wonder_natality.county_natality
ORDER BY
Births DESC
LIMIT
1000
14. Country_of_residence grouped and sorted by Births in Desc
SELECT
County_of_Residence,
Births
FROM
bigquery-public-data.sdoh_cdc_wonder_natality.county_natality
GROUP BY
County_of_Residence,
Births
ORDER BY
Births DESC
LIMIT
1000
15. Used sum to find the total Births count GROUPED BY County_of_residence
SELECT
County_of_Residence,
SUM(Births) AS Total_Births
FROM
bigquery-public-data.sdoh_cdc_wonder_natality.county_natality
GROUP BY
County_of_Residence
ORDER BY
Total_Births DESC
LIMIT
1000

16. Query to Sort columns by dates in Desc and Station_Id in Ascending.


SELECT
stn,
date,
IF(
temp=9999.9,
NULL,
temp) AS temperature,
IF(
wdsp="999.9",
NULL,
CAST(wdsp AS float64)) AS wind_speed,
IF(
prcp=99.99,
0,
prcp) AS precipitation
FROM
bigquery-public-data.noaa_gsod.gsod2020
WHERE
stn="725030" -- La Guardia
OR stn="744860" -- JFK
ORDER BY
date DESC,
stn ASC
17. Created a new table after Running a SQL query
SELECT
stn,
date,
IF(
temp=9999.9,
NULL,
temp) AS temperature,
IF(
wdsp="999.9",
NULL,
CAST(wdsp AS float64)) AS wind_speed,
IF(
prcp=99.99,
0,
prcp) AS precipitation
FROM
`bigquery-public-data.noaa_gsod.gsod2020`
WHERE
stn="725030" -- La Guardia
OR stn="744860" -- JFK
ORDER BY
date DESC,
stn ASC
After saving the above setting a new table inside “demo2” dataset will be created with the name
“nyc_weather”
Combining data from different sources

A. INSERT INTO

Structure of the query

INSERT INTO [destination_table_name]


SELECT [column names, separated by commas, or * for all columns]
FROM [source_table_name]
WHERE [condition]

Example of Query

INSERT INTO customer_promotion


SELECT *
FROM customers
WHERE total_sales = 0 AND postal_code = '12345'

B. CONCAT

Structure of the query

SELECT CONCAT(field1, " ", field2)


FROM [table_name]

SELECT CONCAT(field1, " ", field2) AS alias


FROM [table_name]

Example of the query

SELECT CONCAT(first_name, " ", last_name) AS Customer_Name


FROM [table_name]

18. Merging using CONCAT


SELECT
usertype,
CONCAT (start_station_name," to ", end_station_name) AS route,
COUNT (*) as num_trips,
ROUND(AVG(cast(tripduration as int64)/60),2) AS duration
FROM
`bigquery-public-data.new_york_citibike.citibike_trips`
GROUP BY
start_station_name, end_station_name, usertype
ORDER BY
num_trips DESC
LIMIT 10
Joins Using SQL.

There are four types of JOIN in SQL. Below is the information regarding all the four.

• INNER JOIN: a function that returns records with matching values in both tables
• LEFT JOIN: a function that returns all the records from the left table (first mentioned)
and only the matching records from the right table (second mentioned)
• RIGHT JOIN: a function that returns all records from the right table (second mentioned)
and only the matching records from the left table (first mentioned).
• OUTER JOIN: a function that combines the RIGHT JOIN and LEFT JOIN to return all
matching records in both tables.
In the above SS both the queries will return the same result.

19. INNER JOIN


SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
my-first-project-418418.employee_data.employees AS employees
INNER JOIN
my-first-project-418418.employee_data.departments AS departments
ON employees.department_id = departments.department_id
20. LEFT JOIN
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
my-first-project-418418.employee_data.employees AS employees
LEFT JOIN
my-first-project-418418.employee_data.departments AS departments
ON employees.department_id = departments.department_id

21. RIGHT JOIN


SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
my-first-project-418418.employee_data.employees AS employees
RIGHT JOIN
my-first-project-418418.employee_data.departments AS departments
ON employees.department_id = departments.department_id
22. OUTER JOIN
SELECT
employees.name AS employee_name,
employees.role AS employee_role,
departments.name AS department_name
FROM
my-first-project-418418.employee_data.employees AS employees
FULL OUTER JOIN
my-first-project-418418.employee_data.departments AS departments
ON employees.department_id = departments.department_id

Joins Hands On

23. INNER JOIN


SELECT `bigquery-public-
data.world_bank_intl_education.international_education`.country_name,
`bigquery-public-data.world_bank_intl_education.country_summary`.country_code,
`bigquery-public-data.world_bank_intl_education.international_education`.value
FROM `bigquery-public-data.world_bank_intl_education.international_education`
INNER JOIN `bigquery-public-data.world_bank_intl_education.country_summary`
ON `bigquery-public-data.world_bank_intl_education.country_summary`.country_code =
`bigquery-public-
data.world_bank_intl_education.international_education`.country_code
24. INNER Join Using Alias. (The same above query using Alias)
SELECT
edu.country_name,
summary.country_code,
edu.value
FROM
`bigquery-public-data.world_bank_intl_education.international_education` AS edu
INNER JOIN
`bigquery-public-data.world_bank_intl_education.country_summary` AS summary
ON edu.country_code = summary.country_code

25. Inner Join with Group By


SELECT
edu.country_name,
summary.country_code,
SUM(edu.value) edu_Value
FROM
`bigquery-public-data.world_bank_intl_education.international_education` AS edu
LEFT JOIN
`bigquery-public-data.world_bank_intl_education.country_summary` AS summary
ON edu.country_code = summary.country_code
GROUP BY
edu.country_name,
summary.country_code
ORDER BY
edu_Value DESC
26. INNER JOIN with WHERE Condition

question: In 2015, how many people were of the official age for secondary education broken down by
region of the world?
SELECT
summary.region,
SUM(edu.value) secondary_edu_population
FROM
`bigquery-public-data.world_bank_intl_education.international_education` AS edu
INNER JOIN
`bigquery-public-data.world_bank_intl_education.country_summary` AS summary
ON edu.country_code = summary.country_code --country_code is our key
WHERE summary.region IS NOT NULL
AND edu.indicator_name = 'Population of the official age for secondary
education, both sexes (number)'
AND edu.year = 2015
GROUP BY summary.region
ORDER BY secondary_edu_population DESC
27. LEFT JOIN

Consider this scenario: You have been tasked to provide data for a feature sports article on NCAA
basketball in the 1990s. The writer wants to include a funny twist about which Division 1 team
mascots were the winningest.
SELECT
seasons.market AS university,
seasons.name AS team_name,
mascots.mascot AS team_mascot,
AVG(seasons.wins) AS avg_wins,
AVG(seasons.losses) AS avg_losses,
AVG(seasons.ties) AS avg_ties
FROM `bigquery-public-data.ncaa_basketball.mbb_historical_teams_seasons` AS seasons
LEFT JOIN `bigquery-public-data.ncaa_basketball.mascots` AS mascots
ON seasons.team_id = mascots.id
WHERE seasons.season BETWEEN 1990 AND 1999
AND seasons.division = 1
GROUP BY 1,2,3
ORDER BY avg_wins DESC, university

28. INNER JOIN for Handson activity

SELECT
*
FROM
my-first-project-418418.warehouse_orders.orders AS orders
JOIN
my-first-project-418418.warehouse_orders.warehouse warehouse
ON
orders.warehouse_id = warehouse.warehouse_id
29. Taking All the columns from Orders but only 2 columns from Warehouse

SELECT
orders.*,
warehouse.warehouse_alias,
warehouse.state
FROM
my-first-project-418418.warehouse_orders.orders AS orders
JOIN
my-first-project-418418.warehouse_orders.warehouse warehouse
ON
orders.warehouse_id = warehouse.warehouse_id

30. Using COUNT with INNER Join

SELECT
COUNT(warehouse.state) AS num_States
FROM
my-first-project-418418.warehouse_orders.orders AS orders
JOIN
my-first-project-418418.warehouse_orders.warehouse warehouse
ON
orders.warehouse_id = warehouse.warehouse_id

31. Using DISTINCT COUNT with INNER Join


SELECT
COUNT (DISTINCT warehouse.state) AS num_States
FROM
my-first-project-418418.warehouse_orders.orders AS orders
JOIN
my-first-project-418418.warehouse_orders.warehouse warehouse
ON
orders.warehouse_id = warehouse.warehouse_id
32. USING GROUP BY & ORDER BY & JOIN & COUNT
SELECT
warehouse.warehouse_id,
warehouse.state AS State,
COUNT (warehouse.state) AS num_States
FROM
my-first-project-418418.warehouse_orders.orders AS orders
JOIN
my-first-project-418418.warehouse_orders.warehouse warehouse
ON
orders.warehouse_id = warehouse.warehouse_id
GROUP BY
warehouse.state,
warehouse.warehouse_id
ORDER BY
num_States DESC

NESTED QUERIES
Please find the explaining in the Hands-On Folder of Data Analytics. I have created a word file which
has the explanation for each of the below three queries.
33. USE A SubQuery In a SELECT statement

SELECT
station_id,
num_bikes_available,
(SELECT
AVG(num_bikes_available)
FROM bigquery-public-
data.new_york.citibike_stations) AS avg_num_bikes_available
FROM bigquery-public-data.new_york.citibike_stations;
34. Use a subquery in a FROM statement

SELECT
station_id,
name,
number_of_rides AS number_of_rides_starting_at_station #This column is not
present either in Citibike_trips or Citibike_station so we have created a temporary
table with the name as "station_num_trips" and from that table we are extracting
"number_of_rides".
FROM
(
SELECT
CAST(start_station_id AS STRING) AS start_station_id_str,
COUNT(*) AS number_of_rides
FROM
bigquery-public-data.new_york.citibike_trips
GROUP BY
CAST(start_station_id AS STRING)
) AS station_num_trips
INNER JOIN
bigquery-public-data.new_york.citibike_stations
ON
station_num_trips.start_station_id_str = station_id
ORDER BY
station_num_trips.number_of_rides DESC
35. Use a subquery in a WHERE statement

SELECT
station_id,
name
FROM
bigquery-public-data.new_york.citibike_stations
WHERE
station_id IN
(
SELECT
CAST(start_station_id AS STRING) AS start_station_id_str #**
FROM
bigquery-public-data.new_york.citibike_trips
WHERE
usertype = 'Subscriber'
);
HANDS ON Activity

Data Set used : citibike_trips (Public Data Set)

Scenario : To complete this task, you will create three different subqueries, which will allow you
to gather information about the average trip duration by station, compare trip duration by station,
and determine the five stations with the longest mean trip durations.

36. Query 1 to calculate “ average trip duration by station” (Nested SELECT inside FROM)

SELECT
subquery.start_station_id,
subquery.avg_duration
FROM
(
SELECT
start_station_id,
AVG(tripduration) as avg_duration
FROM bigquery-public-data.new_york_citibike.citibike_trips
GROUP BY start_station_id) as subquery
ORDER BY avg_duration DESC;
37. Query 2 compare “trip duration by station” (Nested SELECT inside SELECT)

SELECT
starttime,
start_station_id,
tripduration,
(
SELECT ROUND(AVG(tripduration),2) #the nested ones are runned when a row
for 1st three columns are ready
FROM bigquery-public-data.new_york_citibike.citibike_trips
WHERE start_station_id = outer_trips.start_station_id
) AS avg_duration_for_station,
ROUND(outer_trips.tripduration - (
SELECT AVG(tripduration)
FROM bigquery-public-data.new_york_citibike.citibike_trips
WHERE start_station_id = outer_trips.start_station_id), 2) AS
difference_from_avg
FROM bigquery-public-data.new_york_citibike.citibike_trips AS outer_trips
ORDER BY difference_from_avg DESC
LIMIT 25;

Regarding 1st Subquery : This subquery is used to calculate the average trip
duration for trips starting at the same station as the current trip
(outer_trips.start_station_id).

38. QUERY 3 compose a new query to filter the data to include only the trips from the five stations
with the longest mean trip duration.
SELECT
tripduration,
start_station_id
FROM bigquery-public-data.new_york_citibike.citibike_trips
WHERE start_station_id IN
(
SELECT
start_station_id
FROM
(
SELECT
start_station_id,
AVG(tripduration) AS avg_duration
FROM bigquery-public-data.new_york_citibike.citibike_trips
GROUP BY start_station_id
) AS top_five
ORDER BY avg_duration DESC
LIMIT 5
);
39. Using CASE to categorize the data.

The use of CASE is very similar to using IF ELSE or SWITCH CASE in java/python
programming.

SELECT
warehouse.warehouse_id,
CONCAT(warehouse.state,': ',warehouse.warehouse_alias) AS warehouse_name,
COUNT(orders.order_id) AS number_of_orders,
(SELECT COUNT(*) FROM my-first-project-418418.warehouse_orders.orders AS orders)
AS total_orders,
CASE
WHEN COUNT(orders.order_id)/(SELECT COUNT(*) FROM my-first-project-
418418.warehouse_orders.orders AS orders) <= 0.2
THEN 'Fullfillment is 0-20%'
WHEN COUNT(orders.order_id)/(SELECT COUNT(*) FROM my-first-project-
418418.warehouse_orders.orders AS orders) > 20
AND COUNT(orders.order_id)/(SELECT COUNT(*) FROM my-first-project-
418418.warehouse_orders.orders AS orders) <= 60
THEN 'Fullfillment is 21-60%'
ELSE 'Fullfillment is more than 60% of orders'
END AS fullfillment_summary
FROM my-first-project-418418.warehouse_orders.warehouse AS warehouse
LEFT JOIN my-first-project-418418.warehouse_orders.orders AS orders
ON orders.warehouse_id = warehouse.warehouse_id
GROUP BY
warehouse.warehouse_id,
warehouse_name
HAVING
COUNT(orders.order_id) > 0
40. Using CASE to categorize the data without HAVING

SELECT
warehouse.warehouse_id,
CONCAT(warehouse.state,': ',warehouse.warehouse_alias) AS warehouse_name,
COUNT(orders.order_id) AS number_of_orders,
(SELECT COUNT(*) FROM my-first-project-418418.warehouse_orders.orders AS orders)
AS total_orders,
CASE
WHEN COUNT(orders.order_id)/(SELECT COUNT(*) FROM my-first-project-
418418.warehouse_orders.orders AS orders) <= 0.2
THEN 'Fullfillment is 0-20%'
WHEN COUNT(orders.order_id)/(SELECT COUNT(*) FROM my-first-project-
418418.warehouse_orders.orders AS orders) > 20
AND COUNT(orders.order_id)/(SELECT COUNT(*) FROM my-first-project-
418418.warehouse_orders.orders AS orders) <= 60
THEN 'Fullfillment is 21-60%'
ELSE 'Fullfillment is more than 60% of orders'
END AS fullfillment_summary
FROM my-first-project-418418.warehouse_orders.warehouse AS warehouse
LEFT JOIN my-first-project-418418.warehouse_orders.orders AS orders
ON orders.warehouse_id = warehouse.warehouse_id
GROUP BY
warehouse.warehouse_id,
warehouse_name
#HAVING
# COUNT(orders.order_id) > 0

Here the number_of_orders column is blank because there are some warehouse_id
numbers which are not present in the orders table.

HANDS ON SCENARIO :

In this scenario, you are a junior data analyst for a multinational food and beverage
manufacturer. You and your team are responsible for maintaining the safety of a wide
array of food products. Because of the overwhelming number of products on the market,
you have been asked to prioritize which products need to be reviewed by your
stakeholders.
While it's useful to know which food industries receive the most complaints, the more
critical aspect to consider is identifying the complaints that lead to severe health
consequences, such as hospital visits.

41. Getting the top 10 Products having most Report Counts.


SELECT
products_industry_name,
COUNT(report_number) AS count_reports
FROM
`bigquery-public-data.fda_food.food_events`
GROUP BY
products_industry_name
ORDER BY
count_reports DESC
LIMIT 10;

42. Getting the top 10 Products having Most Reports as well as those that have most
hospitalizations.
SELECT
products_industry_name,
COUNT(report_number) AS count_reports
FROM
bigquery-public-data.fda_food.food_events
WHERE
products_industry_name IN
(
SELECT
products_industry_name,
-- COUNT(report_number) AS count_reports
FROM
`bigquery-public-data.fda_food.food_events`
GROUP BY
products_industry_name
ORDER BY
COUNT(report_number) DESC
LIMIT 10
) AND outcomes LIKE '%Hospitalization%'
GROUP BY
products_industry_name
ORDER BY
count_reports DESC

SIMPLE Calculations using SQL

43. Simple Addition


SELECT
Date,
Region,
Small_bags,
Large_bags,
XLarge_bags,
Total_bags,
Small_bags + Large_bags + XLarge_bags AS Total_bags_calc
FROM
`my-first-project-418418.avocado_data.avocado_prices`
44. Simple Division to calculate percentage
SELECT
Date,
Region,
Total_bags,
Small_bags,
(Small_bags / Total_bags)*100 AS Small_bags_percent
FROM
`my-first-project-418418.avocado_data.avocado_prices`
WHERE
Total_bags <> 0

45. Use of EXTRACT

In the below query we have used EXTRACT to get the year from the “starttime” column.
SELECT
EXTRACT(YEAR FROM starttime) AS year,
COUNT(*) AS number_of_rides
FROM
`bigquery-public-data.new_york.citibike_trips`
GROUP BY
year
ORDER BY
year
46. HANDSON For basic calculations using SQL.

Subtraction
SELECT
station_name,
ridership_2013,
ridership_2014,
ridership_2014 - ridership_2013 AS change_2014_raw
FROM
`bigquery-public-data.new_york_subway.subway_ridership_2013_present`

47. Calculating AVERAGE


SELECT
station_name,
ridership_2013,
ridership_2014,
ridership_2015,
ridership_2016,
(ridership_2013 + ridership_2014 + ridership_2015 + ridership_2016)/4 AS average
FROM
`bigquery-public-data.new_york_subway.subway_ridership_2013_present`
48. Filtering based on Year, Month, ProductID and StoreID
SELECT
EXTRACT(YEAR FROM Date) AS Year
, EXTRACT(MONTH FROM Date) AS Month
, ProductId
, StoreId
, SUM(Quantity) AS UnitsSold
, AVG(UnitPrice) AS UnitPriceProxy
, COUNT(DISTINCT SalesId) AS NumTransactions
FROM
my-second-project-421106.sales.sales
GROUP BY
Year, Month, ProductId, StoreId
ORDER BY
Year, Month, ProductId, StoreId

49. NESTED Query


with sales_history as (
SELECT
EXTRACT(YEAR FROM Date) AS YEAR --time grouping
, EXTRACT(MONTH FROM Date) AS MONTH --time grouping
, ProductId --need to know which products are sold
, StoreID --need to know which stores are selling
, SUM(quantity) AS UnitsSold --how many (impacts inventory)
, AVG(UnitPrice) AS UnitPriceProxy --can be interesting
, COUNT(DISTINCT salesID) AS NumTransactions --unique transactions can be
interesting
FROM my-second-project-421106.sales.sales
GROUP BY YEAR, MONTH, ProductId, StoreID
)
SELECT
inventory.*
, (SELECT AVG(UnitsSold) FROM sales_history
WHERE inventory.ProductID=sales_history.ProductID
AND inventory.StoreID=sales_history.StoreID) AS avg_quantity_sold_in_a_month
FROM my-second-project-421106.sales.Inventory AS inventory
50. Revised Query using ChatGPT with LEFT JOIN
WITH sales_history AS (
SELECT
EXTRACT(YEAR FROM Date) AS YEAR, -- Extracts the year from the date
EXTRACT(MONTH FROM Date) AS MONTH, -- Extracts the month from the date
ProductId, -- Product ID
StoreID, -- Store ID
SUM(quantity) AS UnitsSold, -- Total units sold
AVG(UnitPrice) AS UnitPriceProxy, -- Average unit price
COUNT(DISTINCT salesID) AS NumTransactions -- Number of unique transactions
FROM my-second-project-421106.sales.sales
GROUP BY YEAR, MONTH, ProductId, StoreID
)

SELECT
inventory.*,
COALESCE(avg_sales.avg_quantity_sold_in_a_month, 0) AS
avg_quantity_sold_in_a_month
FROM
my-second-project-421106.sales.Inventory AS inventory
LEFT JOIN (
SELECT
ProductId,
StoreID,
AVG(UnitsSold) AS avg_quantity_sold_in_a_month
FROM sales_history
GROUP BY ProductId, StoreID
) AS avg_sales
ON inventory.ProductID = avg_sales.ProductID
AND inventory.StoreID = avg_sales.StoreID;
51. Hands-On to find the bikeId having the highest trip duration (Using TEMP Table).

WITH longest_bike_duration AS (
SELECT
bike_id,
SUM(duration_minutes) AS trip_duration
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips`
GROUP BY
bike_id
ORDER BY
trip_duration DESC LIMIT 1
)

## Finding out which bikeid has the highest tripduration

SELECT * FROM longest_bike_duration

52. SQL query to find the name of the station where that bike can most likely be
found, so they ask you to determine which bike is used most often.

WITH longest_bike_duration AS (
SELECT
bike_id,
SUM(duration_minutes) AS trip_duration
FROM
`bigquery-public-data.austin_bikeshare.bikeshare_trips`
GROUP BY
bike_id
ORDER BY
trip_duration DESC LIMIT 1
)

## Finding out which bikeid has the highest tripduration

SELECT
trips.bike_id,
trips.start_station_id,
COUNT(*) AS trip_count
FROM longest_bike_duration AS longest
INNER JOIN
`bigquery-public-data.austin_bikeshare.bikeshare_trips` AS trips
ON trips.bike_id = longest.bike_id
GROUP BY start_station_id, trips.bike_id
ORDER BY trip_count DESC
LIMIT 1
All the below queries actually create a temporary tables into the backend but the
WITH ... AS Command doesn’t actually create a temporary table In the back but
mimics the temporary table.

53. SELECT INTO

(BigQuery currently doesn’t recognize the SELECT INTO command currently below is
the example of how the SELECT INTO might look for other RDBMS system)

3 Ways to create a Temporary Table

You might also like