From b520c1de82603b4242540f24ceebff579a582fa3 Mon Sep 17 00:00:00 2001 From: flykhan Date: Thu, 24 Aug 2023 18:21:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=20sql=20=E6=9F=A5=E8=AF=A2(?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=88=97=EF=BC=8C=E6=9D=A1=E4=BB=B6=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=EF=BC=8C=E6=8E=92=E5=BA=8F=E5=92=8C=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day9/DQL/sch_1.sql | 3 +++ day9/DQL/search1.sql | 4 ++++ day9/DQL/search10.sql | 6 ++++++ day9/DQL/search11.sql | 7 +++++++ day9/DQL/search12.sql | 10 ++++++++++ day9/DQL/search13.sql | 12 ++++++++++++ day9/DQL/search2.sql | 4 ++++ day9/DQL/search3.sql | 5 +++++ day9/DQL/search4.sql | 4 ++++ day9/DQL/search5.sql | 5 +++++ day9/DQL/search6.sql | 5 +++++ day9/DQL/search7.sql | 10 ++++++++++ day9/DQL/search7_2.sql | 11 +++++++++++ day9/DQL/search8.sql | 6 ++++++ day9/DQL/search9.sql | 6 ++++++ 15 files changed, 98 insertions(+) create mode 100644 day9/DQL/sch_1.sql create mode 100644 day9/DQL/search1.sql create mode 100644 day9/DQL/search10.sql create mode 100644 day9/DQL/search11.sql create mode 100644 day9/DQL/search12.sql create mode 100644 day9/DQL/search13.sql create mode 100644 day9/DQL/search2.sql create mode 100644 day9/DQL/search3.sql create mode 100644 day9/DQL/search4.sql create mode 100644 day9/DQL/search5.sql create mode 100644 day9/DQL/search6.sql create mode 100644 day9/DQL/search7.sql create mode 100644 day9/DQL/search7_2.sql create mode 100644 day9/DQL/search8.sql create mode 100644 day9/DQL/search9.sql diff --git a/day9/DQL/sch_1.sql b/day9/DQL/sch_1.sql new file mode 100644 index 0000000..b561e94 --- /dev/null +++ b/day9/DQL/sch_1.sql @@ -0,0 +1,3 @@ +use studb; + + diff --git a/day9/DQL/search1.sql b/day9/DQL/search1.sql new file mode 100644 index 0000000..d3c2170 --- /dev/null +++ b/day9/DQL/search1.sql @@ -0,0 +1,4 @@ +use studb; + +-- 所有列的查询 +select * from t_stu; diff --git a/day9/DQL/search10.sql b/day9/DQL/search10.sql new file mode 100644 index 0000000..2811eae --- /dev/null +++ b/day9/DQL/search10.sql @@ -0,0 +1,6 @@ +use studb; + +-- 查询2022年入职的所有员工 +select * +from t_emp +where hire_date between '2022-01-01' and '2022-12-31'; diff --git a/day9/DQL/search11.sql b/day9/DQL/search11.sql new file mode 100644 index 0000000..21e33db --- /dev/null +++ b/day9/DQL/search11.sql @@ -0,0 +1,7 @@ +use studb; + +-- 按学生的出生日期降序显示 +select * +from t_stu +order by birthday desc; + diff --git a/day9/DQL/search12.sql b/day9/DQL/search12.sql new file mode 100644 index 0000000..914698c --- /dev/null +++ b/day9/DQL/search12.sql @@ -0,0 +1,10 @@ +use studb; + +-- 显示年龄最大的前两位学生 +-- 出去 NULL +select * +from t_stu +where birthday is not null +-- 年龄越大,出生日期越前 +order by birthday asc +limit 0,2; diff --git a/day9/DQL/search13.sql b/day9/DQL/search13.sql new file mode 100644 index 0000000..4ab8d85 --- /dev/null +++ b/day9/DQL/search13.sql @@ -0,0 +1,12 @@ +use studb; + +-- 按1页显示2条数据的方式,显示学生表的第2页数据 + +/* + limit offset, size offset是0开始的, 0表示第一行 + offset = (page-1)*size, page是页号, size是每一页显示的大小 +*/ + +select * +from t_stu +limit 2,2; diff --git a/day9/DQL/search2.sql b/day9/DQL/search2.sql new file mode 100644 index 0000000..81afb1b --- /dev/null +++ b/day9/DQL/search2.sql @@ -0,0 +1,4 @@ +use studb; + +-- 查询指定的列 +select sid, name from t_stu; diff --git a/day9/DQL/search3.sql b/day9/DQL/search3.sql new file mode 100644 index 0000000..9ec31c4 --- /dev/null +++ b/day9/DQL/search3.sql @@ -0,0 +1,5 @@ +use studb; + +-- 查询到的内容按指定的标题显示 +select sid '学号', name as '姓名' +from t_stu; diff --git a/day9/DQL/search4.sql b/day9/DQL/search4.sql new file mode 100644 index 0000000..0481848 --- /dev/null +++ b/day9/DQL/search4.sql @@ -0,0 +1,4 @@ +use studb; + +select t_stu.sid,t_stu.sex +from t_stu; diff --git a/day9/DQL/search5.sql b/day9/DQL/search5.sql new file mode 100644 index 0000000..1259925 --- /dev/null +++ b/day9/DQL/search5.sql @@ -0,0 +1,5 @@ +use studb; + +-- 使用表的别名查询 +select a.* +from t_stu a; diff --git a/day9/DQL/search6.sql b/day9/DQL/search6.sql new file mode 100644 index 0000000..01b0678 --- /dev/null +++ b/day9/DQL/search6.sql @@ -0,0 +1,5 @@ +use studb; + +-- 查询字段是一个表达式 +select sid, name, 100 as score +from t_stu; diff --git a/day9/DQL/search7.sql b/day9/DQL/search7.sql new file mode 100644 index 0000000..7f7585d --- /dev/null +++ b/day9/DQL/search7.sql @@ -0,0 +1,10 @@ +use studb; + +-- 从多个表中查询数据时,如果存在相同的字段时,字段名前必须加表名 +select * +from t_stu t1, t_stu t2; +where t1.sid > 2 and t2.sid > 3; + +/* + 本案例打印结果会出现笛卡尔乘积 +*/ diff --git a/day9/DQL/search7_2.sql b/day9/DQL/search7_2.sql new file mode 100644 index 0000000..c6bf13b --- /dev/null +++ b/day9/DQL/search7_2.sql @@ -0,0 +1,11 @@ +use studb; + +-- 从多个表中查询数据时,如果存在相同的字段时,字段名前必须加表名 +select distinct t1.sid +from t_stu t1, t_stu t2; +where t1.sid > 2 and t2.sid > 3; + +/* + 对7案例的改写,去重 +*/ + diff --git a/day9/DQL/search8.sql b/day9/DQL/search8.sql new file mode 100644 index 0000000..71ed66f --- /dev/null +++ b/day9/DQL/search8.sql @@ -0,0 +1,6 @@ +use studb; + +-- 查询员工表中手机号第7位是8的员工 +select * +from t_emp +where tel like '______8%'; diff --git a/day9/DQL/search9.sql b/day9/DQL/search9.sql new file mode 100644 index 0000000..2d9ce62 --- /dev/null +++ b/day9/DQL/search9.sql @@ -0,0 +1,6 @@ +use studb; + +-- 查询disen和jack两位员工 +select * +from t_emp +where name in ('disen', 'jack');