forked from jetlijetski/Working-With-Functions-MySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice Working with String Functions.sql
More file actions
56 lines (35 loc) · 1.38 KB
/
Copy pathPractice Working with String Functions.sql
File metadata and controls
56 lines (35 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- Replace all the spaces in book title's with an arrow '-->', provide an ALIAS of 'title'
SELECT REPLACE(title, ' ', '->') AS title FROM books;
-- Print two columns with the headings 'forwards' and 'backwards' the authors last name printed forwards and the authors last name printed backwards.
SELECT
author_lname AS forwards,
REVERSE(author_lname) AS 'backwards'
FROM books;
-- Print the authors full name in all caps
SELECT
CONCAT(
UPPER(author_fname),
' ',
UPPER(author_lname))
AS 'full name'
FROM books;
-- Combine the title of the book, with the year it was released in one column
SELECT
CONCAT(title, ' was released in ', released_year)
AS 'Book Release'
FROM books;
-- Print the book titles and the length of each title. Two column headings: one with 'title' and one 'character count'
SELECT
title,
CHAR_LENGTH(title)
AS 'Character Length'
FROM books;
-- Produce three column headings:
-- 1. 'short title' displaying the title of the books with an elipses (...) after the first 10 characters
-- 2. 'author' in the format 'last name,first name'
-- 3. 'quantity' how many of these books are in stock?
SELECT
CONCAT(SUBSTRING(title, 1, 10), '...') AS 'short title',
CONCAT(author_lname, ',', author_fname) AS author,
CONCAT(stock_quantity, ' in stock') AS quantity
FROM books;