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');