Skip to content

Conversation

@simonesquad
Copy link


  <details><summary>hint</summary>

  * This can be done with SELECT and WHERE clauses
  </details>

```SQL
SELECT customer_id, city
FROM customers
WHERE city = 'London'
  • find all customers with postal code 1010. Returns 3 customers

    hint
    • This can be done with SELECT and WHERE clauses
SELECT customer_id, postal_code
FROM customers
WHERE postal_code = '1010'
  • find the phone number for the supplier with the id 11. Should be (010) 9984510

    hint
    • This can be done with SELECT and WHERE clauses
SELECT supplier_id, phone
FROM suppliers
WHERE supplier_id = '11'
  • list orders descending by the order date. The order with date 1998-05-06 should be at the top

    hint
    • This can be done with SELECT, WHERE, and ORDER BY clauses
SELECT customer_id, order_date
FROM orders
ORDER BY order_date DESC
  • find all suppliers who have names longer than 20 characters. Returns 11 records

    hint
    • This can be done with SELECT and WHERE clauses
    • You can use length(company_name) to get the length of the name
SELECT supplier_id, company_name
FROM suppliers
WHERE length(company_name) > '20'
  • find all customers that include the word 'MARKET' in the contact title. Should return 19 records

    hint
    • 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
    • Remember to convert your contact title to all upper case for case insensitive comparing so upper(contact_title)
SELECT contact_title
FROM customers
WHERE upper(contact_title) LIKE '%MARKET%';
  • add a customer record for

  • customer id is 'SHIRE'

  • company name is 'The Shire'

  • contact name is 'Bilbo Baggins'

  • the address is '1 Hobbit-Hole'

  • the city is 'Bag End'

  • the postal code is '111'

  • the country is 'Middle Earth'

    hint
    • This can be done with the INSERT INTO clause
INSERT INTO customers (customer_id, company_name, contact_name, address, city, postal_code, country)
VALUES ('SHIRE', 'The Shire', 'Bilbo Baggins', '1 Hobbit-Hole', 'Bag End', '111', 'Middle Earth');
  • update Bilbo Baggins record so that the postal code changes to "11122"

    hint
    • This can be done with UPDATE and WHERE clauses
UPDATE customers
SET postal_code = '11122'
WHERE contact_name = 'Bilbo Baggins';
  • list orders grouped and ordered by customer company name showing the number of orders per customer company name. Rattlesnake Canyon Grocery should have 18 orders

    hint
    • 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
SELECT count(o.order_date), c.Company_Name
FROM orders o RIGHT JOIN customers c
ON o.customer_id = c.customer_id
GROUP BY c.Company_Name
  • list customers by contact name and the number of orders per contact name. Sort the list by the number of orders in descending order. Jose Pavarotti should be at the top with 31 orders followed by Roland Mendal with 30 orders. Last should be Francisco Chang with 1 order

    hint
    • This can be done by adding an ORDER BY clause to the previous answer and changing the group by field
SELECT count(o.order_date), c.Contact_Name
FROM orders o RIGHT JOIN customers c
ON o.customer_id = c.customer_id
GROUP BY c.Contact_Name
ORDER BY count(o.order_date) DESC
  • list orders grouped by customer's city showing the number of orders per city. Returns 69 Records with Aachen showing 6 orders and Albuquerque showing 18 orders

    hint
    • This is very similar to the previous two queries, however, it focuses on the City rather than the Customer Names
SELECT count(o.order_date), c.city
FROM orders o RIGHT JOIN customers c
ON o.customer_id = c.customer_id
GROUP BY c.city
ORDER BY count(o.order_date) DESC
  • Normalization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant