Giter Site home page Giter Site logo

wip-sql-and-tableau-integration's Introduction

WIP

Combining SQL and Tableau exercise

Problem 1: Create a visualization that provides a breakdown between the male and female employees working in the company each year, starting from 1990.

SELECT
    YEAR(de.from_date) AS Calendar_year,
    e.gender,
    COUNT(e.emp_no) AS num_of_employees
FROM
    t_employees e
        JOIN
    t_dept_emp de ON de.emp_no = e.emp_no
GROUP BY calendar_year , e.gender
HAVING calendar_year >= 1990;

Things to remember

  1. Start by listing out the columns that you want
  2. Which tables do I need? Get the aliases --> adjust the select statement
  3. Remember to use HAVING because COUNT is used and is an aggregate function

Problem 1 Visualisation

Picture1

Problem 2: Compare the number of male managers to the number of female managers from different departments for each year, starting from 1990

SELECT
    d.dept_no, 
    ee.gender, 
    dm.emp_no, 
    dm.from_date, 
    dm.to_date, 
    e.calendar_year, 
    CASE
        WHEN
            YEAR(dm.to_date) >= e.calendar_year 
                AND YEAR(dm.from_date) <= e.calendar_year 
        THEN 
            1 
        ELSE 0 
    END AS active 
FROM 
    (SELECT 
        YEAR(hire_date) AS calendar_year <
    FROM 
        t_employees 
	GROUP BY calendar_year) e 
        CROSS JOIN 
    t_dept_manager dm 
        JOIN 
    t_departments d ON dm.dept_no = d.dept_no 
        JOIN 
    t_employees ee ON dm.emp_no = ee.emp_no 
ORDER BY ee.emp_no AND e.calendar_year; 

Problem 2 Visualisation

Picture1

Problem 3: Compare the average salary of female versus male employees in the entire company until year 2002, and add a filter allowing you to see that per each department.

wip-sql-and-tableau-integration's People

Contributors

mattyapers avatar

Watchers

 avatar

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.