Snowflake for Beginners – Convert Columns Into Rows

Convert Columns Into Rows

UNPIVOT converts a table’s columns into rows.

Create Table Of Superheroes

- Create a table called SUPERHEROES.

CREATE OR REPLACE TABLE SUPERHEROES (
  "ALTER_EGO" VARCHAR(100),
  "AGE" INT,
  "2015" INT,
  "2016" INT,
  "2017" INT,
  "2018" INT,
  "2019" INT
);

Insert Rows For Each Superhero

- Insert rows into SUPERHEROES 
INSERT INTO SUPERHEROES 
    VALUES
    ('The Bomber', 45, 1, 5, 7, 8, 0),
    ('Mr. Money', 12, 1, 5, 7, 8, 2),
    ('Nuke Miner', 5, 3, 5, 5, 6, 2),
    ('The Knife', 43, 1, 2, 9, 8, 0),
    ('Ninka Baker', 32, 1, 5, 3, 8, 1),
    ('Banana Bomber', 34, 1, 3, 2, 8, 2),
    ('Augustine', 12, 1, 5, 7, 8, 0),
    ('The Kid', 21, 1, 5, 7, 3, 3),
    ('The Viking', 291, 2, 3, 7, 8, 0);

Convert Years Columns Into Rows

- Select all columns from SUPERHEROES 
SELECT * FROM SUPERHEROES
- Convert the columns "2015", "2016", "2017", "2018", "2019" into
- rows with appropriate values in a new a YEARS column 
UNPIVOT(YEAR FOR YEARS IN ("2015", "2016", "2017", "2018", "2019"));
ALTER_EGO AGE YEAR KILLS
The Bomber 45 2015 1
The Bomber 45 2016 5
The Bomber 45 2017 7
The Bomber 45 2018 8
The Bomber 45 2019 0
Mr. Money 12 2015 1
Mr. Money 12 2016 5
Mr. Money 12 2017 7
Mr. Money 12 2018 8
Mr. Money 12 2019 2
Nuke Miner 5 2015 3
Nuke Miner 5 2016 5
Nuke Miner 5 2017 5
Nuke Miner 5 2018 6
Nuke Miner 5 2019 2
The Knife 43 2015 1
The Knife 43 2016 2
The Knife 43 2017 9
The Knife 43 2018 8
The Knife 43 2019 0
Ninka Baker 32 2015 1
Ninka Baker 32 2016 5
Ninka Baker 32 2017 3
Ninka Baker 32 2018 8
Ninka Baker 32 2019 1
Banana Bomber 34 2015 1
Banana Bomber 34 2016 3
Banana Bomber 34 2017 2
Banana Bomber 34 2018 8
Banana Bomber 34 2019 2
Augustine 12 2015 1
Augustine 12 2016 5
Augustine 12 2017 7
Augustine 12 2018 8
Augustine 12 2019 0
The Kid 21 2015 1
The Kid 21 2016 5
The Kid 21 2017 7
The Kid 21 2018 3
The Kid 21 2019 3
The Viking 291 2015 2
The Viking 291 2016 3
The Viking 291 2017 7
The Viking 291 2018 8
The Viking 291 2019 0

Python Example for Beginners

Two Machine Learning Fields

There are two sides to machine learning:

  • Practical Machine Learning:This is about querying databases, cleaning data, writing scripts to transform data and gluing algorithm and libraries together and writing custom code to squeeze reliable answers from data to satisfy difficult and ill defined questions. It’s the mess of reality.
  • Theoretical Machine Learning: This is about math and abstraction and idealized scenarios and limits and beauty and informing what is possible. It is a whole lot neater and cleaner and removed from the mess of reality.

Data Science Resources: Data Science Recipes and Applied Machine Learning Recipes

Introduction to Applied Machine Learning & Data Science for Beginners, Business Analysts, Students, Researchers and Freelancers with Python & R Codes @ Western Australian Center for Applied Machine Learning & Data Science (WACAMLDS) !!!

Latest end-to-end Learn by Coding Recipes in Project-Based Learning:

Applied Statistics with R for Beginners and Business Professionals

Data Science and Machine Learning Projects in Python: Tabular Data Analytics

Data Science and Machine Learning Projects in R: Tabular Data Analytics

Python Machine Learning & Data Science Recipes: Learn by Coding

R Machine Learning & Data Science Recipes: Learn by Coding

Comparing Different Machine Learning Algorithms in Python for Classification (FREE)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.  

Google –> SETScholars