From 9e47826564c813110d68b61cbb532413753c10f0 Mon Sep 17 00:00:00 2001 From: iProbe Date: Sun, 28 May 2023 10:16:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93/sql=E5=9F=BA=E7=A1=80.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 数据库/sql基础.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 数据库/sql基础.md diff --git a/数据库/sql基础.md b/数据库/sql基础.md new file mode 100644 index 0000000..fc804b8 --- /dev/null +++ b/数据库/sql基础.md @@ -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'; +```