-
Notifications
You must be signed in to change notification settings - Fork 32
/
regifter.sql
119 lines (79 loc) · 1.91 KB
/
regifter.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
-- Getting started, do not update
DROP DATABASE IF EXISTS regifter;
CREATE DATABASE regifter;
\c regifter
-- End getting started code
--
-- Write your code below each prompt
--
\echo Create a table called gifts
-- with the following columns
-- id serial primary KEY
-- gift - string
-- giver - string
-- value - integer
-- previously_regifted boolean
--
\echo See details of the table you created
--
--
\echo Alter the table so that the column price is changed to value
--
--
\echo Insert a peach candle, given by 'Santa' thats value is 9 and has been previously regifted
--
--
\echo Query for all the columns in your gifts table
--
--
\echo Uncomment below to insert 5 more gifts
--
-- INSERT INTO gifts (gift, giver, value, previously_regifted)
-- VALUES
-- ('peach candle', 'Santa', '9', TRUE),
-- ('cinnamon candle', 'Nick', '19', TRUE),
-- ('soap on a rope', 'Rudolf', '29', FALSE),
-- ('potpurri', 'Elf on the Shelf', '39', TRUE),
-- ('mango candle', 'The Boss', '49', FALSE)
-- ;
--
\echo Insert 5 more gifts of your own choosing, include 1 more candle
--
--
\echo Query for gifts with a price greater than or equal to 20
--
--
\echo Query for every gift that has the word candle in it, only show the gift column
--
--
\echo Query for every gift whose giver is Santa OR value is greater than 30
--
--
\echo Query for every gift whose giver is NOT Santa
--
--
\echo Update the second gift to have a value of 2999
--
--
\echo Query for the updated item
--
--
\echo Delete all the gifts from Santa and return the 'value' and 'gift' of the gift you have deleted
--
--
\echo Query for all the columns in your gifts table one more time
--
-- BONUSES
--
\echo Count the total number of gifts that have the word candle in it
--
--
\echo Get the AVEREAGE value from all the gifts
--
--
\echo Limit to 3 gifts, offset by 2 and order by price descending
--
--
-- finish
--
DROP TABLE IF EXISTS gifts;