Giter Club home page Giter Club logo

sql-practice's Introduction

sql-practice

Create a new database called sql_practice and start with this schema:

CREATE TABLE posts (
     id int auto_increment primary key, 
     title varchar(75), 
     body text
);

References:

Use a MySQL Client Query window to complete the following tasks:

  1. Add a column to represent when this post was created ALTER TABLE posts ADD createdAt DATE;
  2. Add a column to represent what the current status is of the post (draft, publish, archive) ALTER TABLE posts ADD status VARCHAR(10);
  3. Add a column to represent the number of views this post has received ALTER TABLE posts ADD views FLOAT;
  4. Add a column to represent the subtitle for this post ALTER TABLE posts ADD subtitle VARCHAR(50);
  5. Insert a published post created yesterday with a title and body of your choosing INSERT INTO posts (title, body, createdAt, status) VALUES ("Hello world", "Welcome to SQL", '2014-10-27', 'published');
  6. Insert a published post created last Tuesday with 100 views and a title/body of your choosing INSERT INTO posts (title, body, createdAt, status, views) VALUES ("Hello galaxy", "See Sean rock SQL", 'published', '2014-10-21', 100);
  7. Insert a post created today (now) that is a draft and a title/body of your choosing INSERT INTO posts (title, body, createdAt, status) VALUES ("Now", "seize the now!", NOW(), 'draft');
  8. Select all posts that are published SELECT * from posts WHERE status='published';
  9. Select the post with id = 2 SELECT * from posts WHERE id='2';
  10. Select all posts that have more than 1 view SELECT * from posts WHERE views>1;
  11. (Black Diamond) Select all posts that were made in the last two days SELECT * from posts WHERE createdAt>DATE_SUB(NOW(), INTERVAL 2 DAY);

sql-practice's People

Contributors

cahlan avatar tslater avatar metasean avatar

Watchers

James Cloos 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.