添加 '数据库/sql基础.md'

This commit is contained in:
iProbe 2023-05-28 10:16:55 +08:00
parent 70a96349fd
commit 9e47826564

44
数据库/sql基础.md Normal file
View file

@ -0,0 +1,44 @@
## 1. 创建表
```sql
create table ttt(
no int primary key,
name char(10) not null,
depno int,
indate date,
sal numeric(8,2)
);
// numrtic(a,b): 数字类型总位数为8小数点后b位
// char(a): 定长为a的字符串
// varchar(a): 变长字符串最大长度为a
```
## 2. 删除表
```sql
drop table ttt;
drop table ttt if exists;
```
## 3. 插入
```sql
insert into ttt values(1,"ttt",1,"2023-05-28",12.33);
insert into ttt(no,name,depno,indate,sal) values(1,"ttt",1,"2023-05-28",12.33);
insert into ttt(no,name,depno) values(1,"ttt",1);
```
## 4. distinct去除重复
```sql
selet distinct depno from ttt;
```
## 5.查询多个值
```sql
select name from ttt where depno in (2,3,5);
select name from ttt where depno not in (2,3,5);
```
## 6. between
```sql
select name from ttt where indate between '2022-01-22' and '2023-04-30';
// 等价
select name from ttt where indate>='2022-01-22' and indate<>='2023-04-30';
select name from ttt where indate not between '2022-01-22' and '2023-04-30';
```