-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab6.sql
88 lines (73 loc) · 1.53 KB
/
Lab6.sql
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use books;
# Display all info
select
title_id,
title_name,
price,
round(price*.10,2) as "Discount",
round(price*.90,2) as "New Price"
from
titles;
# Display all authors names
select
concat(au_lname,", ",au_fname) as "Name"
from
authors;
# Display all search id and names of the authors
select
concat(substr(upper(au_lname) from 1 for 3),"", substr(phone from 9 for 12)) as "Search ID",
concat(au_lname,", ",au_fname) as "Name"
from
authors;
# Display all the authors names and how long they are
select
au_lname,
character_length(au_lname) as "Length"
from
authors;
# Display all the books IDs, titles, and year of publication
select
title_id,
title_name,
extract(year from pubdate) as "year"
from
titles;
# Display all the book ids, titles, publication date and copyright expire date(28 years).
select
title_id,
title_name,
pubdate,
pubdate + interval 28 year as "Copyright Date"
from
titles;
# Display all book ids, titles, price, and new price (10% off history books 20% for everything else)
select
title_id,
title_name,
price,
CASE type
WHEN 'history'
THEN price - (price*.10)
ELSE price - (price*.20)
END
AS "New Price"
from
titles;
# Display all ids, names and price of books. (Note the priceless book)
select
title_id,
title_name,
CASE type
WHEN price IS NOT NULL
THEN 'Priceless'
ELSE price
END
AS "retail"
from
titles;
# Display the current date and time.
select
CURRENT_TIMESTAMP AS "Current Time";
# Display the current host machine.
select
substr(CURRENT_USER from 6 for 12) AS "Server";