-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.sql
119 lines (100 loc) · 2.07 KB
/
query.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
-- name: GetCustomer :one
SELECT * FROM customer
WHERE id = ? LIMIT 1;
-- name: ListCustomer :many
SELECT * FROM customer
ORDER BY customer_name;
-- name: CreateCustomer :execresult
INSERT INTO customer (
customer_name, contact_name, address, city, postal_code, country
) VALUES (
?, ?, ?, ?, ?, ?
);
-- name: UpdateCustomer :execresult
UPDATE customer
SET
customer_name = ?,
contact_name = ?,
address = ?,
city = ?,
postal_code = ?,
country = ?
WHERE
id = ?;
-- name: CreateCategorie :execresult
INSERT INTO categorie (
category_name, description
) VALUES (
?, ?
);
-- name: CreateEmployee :execresult
INSERT INTO employee (
last_name, first_name, birth_date, photo, notes
) VALUES (
?, ?, ?, ?, ?
);
-- name: CreateShipper :execresult
INSERT INTO shipper (
shipper_name, phone
) VALUES (
?, ?
);
-- name: CreateSupplier :execresult
INSERT INTO supplier (
supplier_name, contact_name, address, city, postal_code, country, phone
) VALUES (
?, ?, ?, ?, ?, ?, ?
);
-- name: CreateOrder :execresult
INSERT INTO orders (
id, customer_id, employee_id, shipper_id, order_date
) VALUES (
?, ?, ?, ?, ?
);
-- name: CreateProduct :execresult
INSERT INTO product (
product_name, supplier_id, category_id, unit, price
) VALUES (
?, ?, ?, ?, ?
);
-- name: CreateOrderDetail :execresult
INSERT INTO order_detail (
order_id, product_id, quantity
) VALUES (
?, ?, ?
);
-- name: DeleteCustomer :exec
DELETE FROM customer
WHERE id = ?;
-- name: OrdersAssocaitedWithCustomer :many
SELECT
c.id AS customer_id,
c.customer_name,
c.contact_name,
c.address,
c.city,
c.postal_code,
c.country,
o.id AS order_id,
o.order_date,
od.id AS order_detail_id,
p.product_name,
od.quantity,
p.price,
CAST((od.quantity * p.price) AS FLOAT) AS total_amount
FROM
customer c
LEFT JOIN
orders o ON c.id = o.customer_id
LEFT JOIN
order_detail od ON o.id = od.order_id
LEFT JOIN
product p ON od.product_id = p.id
WHERE
c.id = ?;
-- name: SoftDeleteCustomer :exec
UPDATE customer
SET
deleted_at = ?
WHERE
id = ?;