Giter Site home page Giter Site logo

jesse042811 / sql_case_study Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 8 KB

Tables given with ID, Datetime, metricName, and metricValue, but want to repivot in a manner where we can focus on specific metricName and tracks which versions they used based on the metricValue column.

sql_case_study's Introduction

SQL_case_study

Tables given with ID, Datetime, metricName, and metricValue, but want to repivot in a manner where we can focus on specific metricName and tracks which versions they used based on the metricValue column.

I've posted by solution in finalSQL.sql. Feel free to leave a comment on how I can improve the solution

Requirements/Information

Convert a table of metrics into a Version history table

  • We need to convert the contents of the data.csv file into the contents of the finalData.csv file
  • Version1 is a major software update
  • Version2 is a minor software update

Desired Final Format

clientID dateTime Version1 Version2
A 2021-01-01 1.0 A1
A 2021-01-02 1.0 A2
B 2022-01-01 3.0 A4

Must use SQL to keep as much processing in one system as possible

  • This would be easier in Python or R but then we’d have to extract the data from the database, transform it, then reimport it

For each deviceID, there’s only a record when there’s an update to the system

If we just pivot our records then we get a lot of nulls

Resources

The initial data is in data.csv

You can insert the data into https://sqliteonline.com/ for a quick and easy SQL Database

What You'll Learn / Use

My solution uses:

  • The PIVOT operator
  • WITH to create a Continuous Table Expression (CTE)
  • OVER to use window functions

Credit for solution

https://www.andrewvillazon.com/forward-fill-values-t-sql/#:~:text=To achieve the forward-filling,current row value is NULL .&text=Now we can SELECT the,rows come out as expected.&text=At this point%2C we've forward-filled

sql_case_study's People

Contributors

jesse042811 avatar

Watchers

 avatar

Forkers

roadblock042899

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.