Workshop

The quiz and exercises are provided to help you solidify your understanding of the material covered today. Try to understand the quiz and exercise answers before continuing to tomorrow's lesson.

Quiz

1:Is it possible to decode a string that has been encrypted with PASSWORD()?
A1: No.
2:What's wrong with the query:
SELECT ADD_PERIOD (200304, 8)

A2: The function should be PERIOD_ADD(), and there cannot be a space before the opening parenthesis.
3:What is returned by:
SELECT 'Hello' - '22'

A3: The number -22.
4:What is the result of:
SELECT 'Hello World' RLIKE 'b|c|d'

A4: 1, meaning true.

Exercises

1:Write a query to run on a table invoices that returns all columns where the invoice was produced more than one week ago (according to the column invoice_date).
A1: SELECT * FROM invoices WHERE NOW() - INTERVAL 7 DAY > invoice_date
2:What will be the output of the following query? Why?
SELECT 1 - 10 * 2

A2: -19. The multiplication (*) is evaluated first, and the subtraction (-) second.
3:Write an expression, without using regular expressions, that returns 1 if a string has only a single character; otherwise, 0.
A3: SELECT LENGTH("string")=1
4:Repeat Exercise 3 using REGEXP, but this time only return a 1 if the string has just one letter, upper- or lowercase.
A4: SELECT "string" REGEXP "^[a-zA-Z]$"
5:Why is the following statement badly formatted?
SELECT * FROM friends WHERE birth_date > '80-01-01'

A5: It will yield an incorrect result. The dates will be compared as strings and give an incorrect result because only two-digit years are being used. Always use four-digit years in comparisons, and always use leading zeros in dates and times.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.204.201