0% found this document useful (0 votes)
4 views3 pages

SQL Examples

The document contains a table of cookie orders with customer details, including customer ID, name, item ordered, and quantity. It includes SQL statements for extracting customer information based on specific conditions, updating item names, and inserting a new customer. Additionally, it poses questions regarding data types, validation checks, and string manipulation methods related to the customer names.

Uploaded by

olannaokwuonu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

SQL Examples

The document contains a table of cookie orders with customer details, including customer ID, name, item ordered, and quantity. It includes SQL statements for extracting customer information based on specific conditions, updating item names, and inserting a new customer. Additionally, it poses questions regarding data types, validation checks, and string manipulation methods related to the customer names.

Uploaded by

olannaokwuonu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Cookie_Orders

customer_ID customerName item_ordered Quantity


1 Bob Chocolate chip 5
2 Sally Oatmeal 3
3 Tia White chocolate 2
4 Bobby Raisin 1
5 Lou Ginger nut 1
6 Jo Chocolate chip 6
7 Liam Smarties 8
8 Rue Raisin 12

1. Write a SQL statement to extract the customer_ID and customer name for everyone who
has ordered a Smarties cookie, in order of customer name.
2. Write a SQL statement to extract the customer_ID and item_ordered for everyone who’s
ordered more than 5 cookies.
2i. Write the results of this SQL Statement.

3. Write a SQL Statement to update the item_ordered of chocolate chip to CC where at least
3 have been ordered. 3

3i. Write a SQL Statement to update the item_ordered of Ginger nut to nn where only one
has been ordered.
4. Write a SQL Statement for a new customer: CustomerName: Bertie, Item_ordered
Oatmeal, Quantity 2.

Other unit, related questions:


1. What data types are present in this table?
2. What validation checks could you apply to each of the fields?
3. Can you write a list/array of all the names? Demonstrate some string manipulation
methods on these.
customer_ID customerName item_ordered Quantity
1 Bob Chocolate chip 5
2 Sally Oatmeal 3
3 Tia White chocolate 2
4 Bobby Raisin 1
5 Lou Ginger nut 1
6 Jo Chocolate chip 6
7 Liam Smarties 8
8 Rue Raisin 12
With *some hints*
Cookie_Orders

1. Write a SQL statement to extract the customer_ID and customer name for everyone who
has ordered a Smarties cookie, in order of customer name.

SELECT field names separated by comma FROM table number WHERE condition ORDER BY
field name.
2. Write a SQL statement to extract the customer_ID and item_ordered for everyone who’s
ordered more than 5 cookies.

SELECT customer_ID, item_ordered FROM Cookie_Orders WHERE Quantity >5


2i. Write the results of this SQL Statement.
Check which fields you want, then the condition. Check if it’s inclusive of the number or
not.
3. Write a SQL Statement to update the item_ordered of chocolate chip to CC where at least
3 have been ordered.
-write UPDATE, name of table, SET, field you want to change, WHERE, condition

4. Write a SQL Statement for a new customer: CustomerName: Bertie, Item_ordered


Oatmeal, Quantity 2.

Write INSERT INTO, table name, fields you’re wanting to add into (in brackets), VALUES,
items you want adding in – remembering “” for strings.
ANSWERS:

1. Write a SQL statement to extract the customer_ID and customer name for everyone who
has ordered a Smarties cookie, in order of customer name.
SELECT customer_ID, customerName FROM Cookie_Orders WHERE item_ordered =
“Smarties” ORDER BY customerName.
2. Write a SQL statement to extract the customer_ID and item_ordered for everyone who’s
ordered more than 5 cookies.

SELECT customer_ID, item_ordered FROM Cookie_Orders WHERE Quantity >5


2i. Write the results of this SQL Statement.
6 Chocolate chip
7 Smarties
8 Raisin
3. Write a SQL Statement to update the item_ordered of chocolate chip to CC where at least
3 have been ordered.
UPDATE Cookie_orders SET item_ordered= ‘CC’ WHERE Quantity >=3>3
UPDATE Cookie_orders SET item_ordered= ‘CC’ WHERE Quantity >2
3. Write a SQL Statement to update the item_ordered of Ginger nut to nn where only one
has been ordered.
UPDATE Cookie_Orders SET item_ordered = ‘nn’ WHERE Quantity = 1

4. Write a SQL Statement for a new customer: CustomerName: Bertie, Item_ordered


Oatmeal, Quantity 2.

INSERT INTO Cookie_Orders (CustomerName, Item_ordered, Quantity) VALUES (“Bertie”,


“Oatmeal”, 2)

You might also like