Git Product home page Git Product logo

sample-database's Introduction

sample-database

sample database to practice queries

use the provided HTML file

Browse to https://irooc.github.io/sample-database and start quering. That page will load with the create-schema.sql file so you can start querying right away. This file is intenionally selfcontained but it loads the create-schema file from the same folder, as an alternative you could just execute the sql the first time. For the 'hacking' excersize the file contains a sql-injection like handling of the queries to show the basics of this. This is not intended to be a complete explanation.

use existing demo database on sqliteonline

Clone the repository to a local folder

git clone https://github.com/IRooc/sample-database.git

Go to https://sqliteonline.com and select File > Open DB from the menu and select the file sqlite_pizza_demo.db from the local folder.

or create new the database on sqliteonline

Go to https://sqliteonline.com and paste in the contents from create-schema.sql and click RUN.

start querying

You now have a filled database where you can look around and start querying.

Example Query, (ingredient usage for all normal pizza's):

SELECT ingredients.Name, ingredients.portionsize * SUM(pizza_ingredients.portions) UsedAmount, COUNT(*) UsedCount
FROM pizza 
JOIN pizza_ingredients on pizza.ID = pizza_ingredients.PizzaID
JOIN ingredients on ingredients.ID = pizza_ingredients.IngredientID
GROUP BY ingredients.Name, ingredients.portionsize

Query getting the ingredients used in current orders:

SELECT IFNULL(ingredients2.Name, ingredients.Name), count(*)
FROM orders
JOIN order_lines on orders.ID = order_lines.orderid
LEFT JOIN order_custom_ingredients ON order_lines.ID = order_custom_ingredients.OrderLineID
LEFT JOIN ingredients ingredients2 on order_custom_ingredients.IngredientID = ingredients2.id
LEFT JOIN pizza on order_lines.pizzaid = pizza.id
LEFT JOIN pizza_ingredients ON pizza.id = pizza_ingredients.pizzaid
LEFT JOIN ingredients on pizza_ingredients.ingredientid = ingredients.id
GROUP BY IFNULL(ingredients2.name, ingredients.name)

sample-database's People

Contributors

irooc 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.