常用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
-- 删除表
drop table if exists orders;
-- 创建表
create table if not exists orders (
id int primary key auto_increment,
order_id varchar(255) not null unique,
posted_date date not null,
country_code varchar(255) not null,
amount decimal(10, 2) not null
);
-- 插入数据
insert ignore into orders (order_id, posted_date, country_code, amount)
values ('amz_tk001', '2025-01-01', 'US', 100.00);
insert ignore into orders (order_id, posted_date, country_code, amount)
values ('amz_tk002', '2025-01-02', 'US', 50.00),
('amz_tk003', '2025-01-03', 'US', 75.00),
('amz_tk004', '2025-01-04', 'US', 125.00);
insert ignore into orders
values (default, 'amz_tk005', '2025-01-05', 'US', 85.00),
(default, 'amz_tk006', '2025-01-06', 'US', 225.00);
insert ignore into orders (order_id, posted_date, country_code, amount)
values ('amz_tk001', '2025-01-01', 'US', 250.00)
on duplicate key update amount = values(amount);
This post is licensed under CC BY 4.0 by the author.