SQL group by,between and,union,having

 时间:2024-11-06 11:11:26

union运算符,外连接,group分组,betweenand,having

工具/原料

mysql

SQLyog

方法/步骤

1、学生表studentCREATETABLE`s隋茚粟胫tudent`(`id`int(50)NOTNULLAUTO_INCREMENT,`name际吨孔鳝`varchar(50)DEFAULTNULL,`sex`varchar(48)DEFAULTNULL,`age`varchar(50)DEFAULTNULL,`birthday`varchar(50)DEFAULTNULL,PRIMARYKEY(`id`))ENGINE=InnoDBAUTO_INCREMENT=245DEFAULTCHARSET=utf8

SQL group by,between and,union,having

2、课程表kechengCREATETABLE`kecheng`(螬绣囤扮`id`int(11)NOTNULL荑樊综鲶,`yuwen`int(11)DEFAULTNULL,`shuxue`int(11)DEFAULTNULL,`yinyu`int(11)DEFAULTNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=utf8

SQL group by,between and,union,having

3、分组(学生表分组通过班级,查看每班要多少个人)GroupbySELECTs.class,COUNT(*)FROMstudentsGROUPBYs.class

SQL group by,between and,union,having

SQL group by,between and,union,having

4、外连接(学生表和课程表,找到2个表直接id一样的学生)SELECT*FROMstudents,kechengkWHEREs.id=k.id

SQL group by,between and,union,having

SQL group by,between and,union,having

SQL group by,between and,union,having

5、betweenand(找到年龄在20到40之间的学生)SELECT*FROMstudentsWHEREs.ageBETWEEN20AND40

SQL group by,between and,union,having

SQL group by,between and,union,having

6、having(having和groupby一起用了,可以对分组以后的数据进行处理)(以班级分组,每班的学生的年龄之和小于50)SELECTs.class,COUNT(*),SUM(age)FROMstudentsGROUPBYs.classHAVINGSUM(age)<50

SQL group by,between and,union,having

SQL group by,between and,union,having

7、union(合并的字段必须是相同的了)(合并一下id了)

SQL group by,between and,union,having

SQL group by,between and,union,having

SQL group by,between and,union,having

如何设置电脑语音输入法添加标点符号? Excel如何将数据重复指定次数 如何使用Excel中的定位功能实现快速填充 如何组织专题调研工作? Excel如何快速提取唯一值
热门搜索
龙吐珠图片 十大功劳图片 蝴蝶犬图片 树叶贴画图片大全简单 黑丝图片