GithubHelp home page GithubHelp logo

java-sql's Introduction

Introduction

Working with SQL

Instructions

Surf to SQL Try Editor at W3Schools.com
Answer the following data queries. Keep track of the SQL you write by pasting it into this document under its appropriate header below. You will be submitting that through the regular fork, change, pull process.

Clicking the Restore Database button in the page will repopulate the database with the original data and discard all changes you have made.

find all customers that live in London. Returns 6 records.

This can be done with SELECT and WHERE clauses

find all customers with postal code 1010. Returns 3 customers.

This can be done with SELECT and WHERE clauses

find the phone number for the supplier with the id 11. Should be (010) 9984510.

This can be done with SELECT and WHERE clauses

list orders descending by the order date. The order with date 1997-02-12 should be at the top.

This can be done with SELECT, WHERE, and ORDER BY clauses

find all suppliers who have names longer than 20 characters. You can use length(SupplierName) to get the length of the name. Returns 11 records.

This can be done with SELECT and WHERE clauses

find all customers that include the word "market" in the name. Should return 4 records.

This can be done with SELECT and a WHERE clause using the LIKE keyword

Don't forget the wildcard '%' symbols at the beginning and end of your substring to denote it can appear anywhere in the string in question

add a customer record for "The Shire", the contact name is "Bilbo Baggins" the address is "1 Hobbit-Hole" in "Bag End", postal code "111" and the country is "Middle Earth".

This can be done with the INSERT INTO clause

update Bilbo Baggins record so that the postal code changes to "11122".

This can be done with UPDATE and WHERE clauses

list orders grouped by customer showing the number of orders per customer. Rattlesnake Canyon Grocery should have 7 orders.

This can be done with SELECT, COUNT, JOIN and GROUP BY clauses. Your count should focus on a field in the Orders table, not the Customer table

There is more information about the COUNT clause on W3 Schools

list customers names and the number of orders per customer. Sort the list by number of orders in descending order. Ernst Handel should be at the top with 10 orders followed by QUICK-Stop, Rattlesnake Canyon Grocery and Wartian Herkku with 7 orders each.

This can be done by adding an ORDER BY clause to the previous answer

list orders grouped by customer's city showing number of orders per city. Returns 58 Records with Aachen showing 2 orders and Albuquerque showing 7 orders.

This is very similar to the previous two queries, however, it focuses on the City rather than the CustomerName

delete all customers that have no orders. Should delete 17 (or 18 if you haven't deleted the record added) records.

This is done with a DELETE query

In the WHERE clause, you can provide another list with an IN keyword this list can be the result of another SELECT query. Write a query to return a list of CustomerIDs that meet the criteria above. Pass that to the IN keyword of the WHERE clause as the list of IDs to be deleted

Use a LEFT JOIN to join the Orders table onto the Customers table and check for a NULL value in the OrderID column

Create Database and Table

Keep track of the code you write and paste at the end of this document

  • use SQLite Studio to create a database, name it budget.sqlite3.

  • add an accounts table with the following schema:

    • id, numeric value with no decimal places that should autoincrement.
    • name, string, add whatever is necessary to make searching by name faster.
    • budget numeric value.
  • constraints

    • the id should be the primary key for the table.
    • account name should be unique.
    • account budget is required.

This can be done with the CREATE TABLE clause

java-sql's People

Contributors

jrmmba8314 avatar chancepayne 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.