-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sql
60 lines (49 loc) · 1.32 KB
/
update.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
/*table data taken from the MYSQL WORKBENCH*/
/*update rows*/
UPDATE invoices
SET payment_total = 10,payment_date = '2019-03-01'
WHERE invoice_id = 1
/*if we entered wrong data*/
UPDATE invoices
SET payment_total = DEFAULT,payment_date = NULL
WHERE invoice_id = 1
UPDATE invoices
SET payment_total = invoice_total * 0.5,
payment_date = due_date
WHERE invoice_id = 3
/*-------------------------------*/
UPDATE customers
SETg points = points +50
WHERE birth_date < '1990-01-01'
/*update multiple rows */
UPDATE invoices
SET payment_total = invoice_total * 0.5,
payment_date = due_date
WHERE invoice_id IN (3,4) --change the settings in the MYSQL
/*subqueries in updating rows*/
UPDATE invoices
SET payment_total = invoice_total * 0.5,
payment_date = due_date
WHERE invoice_id=
(SELECT client_id
FROM clients
WHERE name = 'Myworks')
UPDATE invoices
SET payment_total = invoice_total * 0.5,
payment_date = due_date
WHERE invoice_id IN
(SELECT client_id
FROM clients
WHERE state IN ('CA','NY')
/*-------------------------------*/
UPDATE invoices
SET payment_total = invoice_total * 0.5,
payment_date = due_date
WHERE payment_date IS NULL
/*----------------------------*/
UPDATE orders
SET comments = 'Gold customers'
WHERE customer_id IN (
SELECT customer_id
FROM customers
WHERE points > 3000 )