在dos命令窗口输入:
连接到数据库:
mysql -u root -p123456
在mysql环境中输入:
查看当前连接下的数据库:
show databases;
显示当前使用的数据库
select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
表示未选择数据库
选择数据库:
use test01;
use test02;
新建数据库test03,并且设置字符编码为
utf8
create database test03
charset='UTF8';
show databases;
| test01 |
| test02 |
| test03 |
+--------------------+
use test03;
select database();
查看当前数据库下的所有表
show tables;
新建表 stu
create table stu(
id int primary key,
name varchar(20) not null,
age int
);
show tables;
1 使用命令行连接到mysql
mysql -u root -p123456
2 查看当前连接下的所有数据库
show databases;
3 新建数据库web01
create database
web01;charset='utf8';
4 选择数据库web01
use web01;
5 查看当前使用数据库:
select database();
6 查看当前数据库下的所有数据表
show tables;
7 新建表test01 id name score
create table test01(
id int primary key,
name varchar(50) not null,
score int not null
)
insert into test01 values
(1,'zs',99),(2,'ls',89),(3,'ww',99),
(4,'zl',98),(5,'ml',95),(6,'zs',92),
(7,'zq',96),(8,'xl',86),
(9,'zs',88);
mysql -u root -p123456
use web01;
insert into test01 values
(10,'zs',88);
desc test01;
select * from test01;
insert into test01 values
(11,'hh',81),(12,'hb',85),
(13,'mk',86);
select id from test01;
select id,name from test01;
下午 :
1 连接到数据库
在DOS窗口输入:
mysql -u root -p123456
进入mysql环境,以后输入的
每条命令都要以英文的分号结尾,
代码中的标点符号必须是英文状态。))
"" “”
2 查看当前连接下的数据库:
show databases;
3 新建数据库 web02;
create database web02;
create database web02
charset='utf8';
4 删除数据库web02;
drop database web02;
create database web02
charset='utf8';
5 使用数据库web02;
use web02;
6 查看当前使用的数据库:
select database();
7 查看当前数据库下的所有数据表
show tables;
8 新建表 stu id name age
create table stu(
id int primary key,
name varchar(20) not null,
age int
);
varchar 可变长字符串,占用的空间取决
于实际使用字符串长度。
查看表是否创建成功
show tables;
9 插入数据
insert into stu values(1,'zs',16);
10 一次性插入多条数据
insert into stu values
(2,'zs02',16),(3,'zs03',15),
(4,'zs04',17),(5,'zs05',19),
(6,'zs06',18),(7,'zs07',16),
(8,'zs08',18),(9,'zs09',19),
(10,'zs10',15),(11,'zs11',16);
11 按列插入数据:
insert into stu(name,id) value
('ls',16);
12 查看表中数据
select * from stu ;
null 空
13 查看表结构
desc stu;
14 查看表中指定列的数据
select id from stu ;
select name from stu ;
select id , name from stu ;
15 查看id=1的这条记录
select * from stu
where id = 1 ;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | zs | 16 |
+----+------+------+
Empty set (0.00 sec)
16 查询name='zs08'的这条记录
select *
from stu
where name = 'zs08' ;
17 查询出 age = 16 的记录
select *
from stu
where age = 16 ;
+----+------+------+
| id | name | age |
| 1 | zs | 16 |
| 2 | zs02 | 16 |
| 7 | zs07 | 16 |
| 11 | zs11 | 16 |
+----+------+------+
18 数据类型:
18.1 整数类型
int 整型 表示在+-21亿范围之内
的整数,都可以划入int的范围
20000 * 12 * 40 = 9600000
18.2 浮点型
1000 1 E 3= 1*10^3
float 单精度浮点型
double 双精度浮点型
18.3 字符串类型
char 定长字符串 '男' '女'
varchar 可变长字符串 20 5
18.4 日期类型
date 2002-1-1
19 新建一个商品表 goods
id int primary key,
name varchar(50) not null,
price float(6,2) not null,
date date
create table goods(
id int primary key,
name varchar(50) not null,
price float(6,2) not null,
date date
);
20 插入数据
insert into goods values(1,'运动服
',88.88,'2020-11-24');
select * from goods;
set names gbk;
21 再插入15条数据
作业:
1 连接数据库
2 查看当前连接下的数据库
3 新建数据库 testabc
4 使用 testabc
5 新建表 emp
id
name
age
birthday
6 插入20条数据
7 查询出emp表中所有数据
8 查询出id=5 的这条记录
9 查询出某个人的信息
10 查询出所有员工的生日
+-------+-------------+------+-----
+---------+-------+
| Field | Type | Null | Key |
Default | Extra |
+-------+-------------+------+-----
+---------+-------+
| id | int(11) | NO | PRI |
NULL | |
| name | varchar(50) | NO | |
NULL | |
| score | int(11) | NO | |
NULL | |
+-------+-------------+------+-----
+---------+-------+
set names gbk;
not exist 不存在
11月25日:
1 连接到数据库
win R --> cmd -->dos命令窗口
mysql -u root -p123456
2 把me.sql的内容复制进去执行
3
INSERT INTO s_emp VALUES (
1, 'Velasquez', 'Carmen',
'cvelasqu',
'19900306', NULL, NULL,
'President',
50, 2500, NULL);
CREATE TABLE s_emp
(id 员工编号 int primary key ,
last_name 姓 VARCHAR(25) NOT
NULL,
first_name 名 VARCHAR
(25),
userid 用户编号 VARCHAR(8),
start_date 入职日期 DATE,
comments 个人情况说明 VARCHAR
(255),
manager_id 领导id int ,
title 职位 VARCHAR
(25),
dept_id 部门编号 int,
salary 月薪 double(11,
2),
commission_pct 提成 double(4,
2),
CONSTRAINT s_emp_userid_uk
UNIQUE (userid),
CONSTRAINT
s_emp_commission_pct_ck
CHECK (commission_pct IN (10,
12.5, 15, 17.5, 20)));
INSERT INTO s_emp VALUES (
26, '张三', '张三', 'zs',
'20200208', NULL, NULL, 'bz',
41, 1000, NULL);
commit; 提交
id | last_name | first_name |
userid | start_date | comments |
manager_id
| title | dept_id |
salary | commission_pct |
查看当前数据库下的所有表
show tables;
create table stu(
id int primary key,
name varchar(20) not null,
age int
);
insert into stu values
(1,'Tom',8),(2,'Rose',7),
(3,'Jack',9),(4,'Jerry',6);
select * from stu;
4 修改数据
4.1 修改表名
rename table stu to student;
show tables;
rename table student to stu;
rename 重命名
4.2 添加列
alter table stu add column
addr varchar(50);
alter 修改 table 表 stu 表名
add 添加 column 列 addr要添加的列的列
名 varchar(50) 要添加列的数据类型
修改表stu添加新字段addr 字段数据
类型为varchar(50)
4.3 删除列
desc stu;
alter table stu drop column
addr;
drop 删除
4.4 修改字段的数据类型
把name字段的数据类型由varchar
(20)修改为varchar(10)
alter table stu modify name
varchar(10);
modify 定义
4.5 重命名列
把age字段重命名为nianling
alter table stu change column age
nianling int ;
change 改变
alter table stu change column
nianling age int ;
4.6 修改stu表的name值为'擎天柱'
update stu set name = '擎天柱';
update 修改 set 设置
这行代码后面没有条件,会把表中数
据的name值全部修改为擎天柱
select * from stu;
4.7 添加where子句,添加条件
把id=1的这条记录的name值修改为
大黄蜂
update stu
set name = '大黄蜂'
where id = 1;
把id=2的这条记录的name值修改为
威震天,年龄修改为6000
update stu
set name = '威震天',age = 6000
where id = 2;
5 删除表中数据
delete from stu
where id = 4 ;
delete 删除
from 从 stu 表名
where 哪里 条件
后面跟的就是条件
delete from stu
where id = 3 ;
删除表中所有数据:
delete from stu;
desc stu;
6 删除表:
drop table stu;
7 查询语句
7.1 查询s_emp表中的所有数据
select * from s_emp;
select 选择
* 代表表中所有的列
from 从 s_emp 表名
delete from s_emp
where id = 26 ;
s_emp 是员工表
7.2 查询员工的姓名,月薪
select first_name , salary
from s_emp;
7.3 查询员工的姓名和年薪
select first_name , salary*12
from s_emp;
| first_name | salary*12 |
+------------+-----------+
| Carmen | 30000.00 |
| LaDoris | 17400.00 |
| Midori | 16800.00 |
这个结果没有包含有提成的人的提
成收入,是不准确的
7.3.1 查询哪些人有提成
select
first_name,commission_pct
from s_emp;
| Colin | 10.00 |
| Henry | 12.50 |
| Yasmin | 10.00 |
| Mai | 15.00 |
| Andre | 17.50|
年薪= 月薪 *(1+提成)*12
select first_name , salary*
(1+(commission_pct/100))*12
from s_emp;
| first_name | salary*
(1+(commission_pct/100))*12 |
+------------+----------------------+
| Carmen NULL |
| LaDoris NULL |
| Colin 18480.000000 |
引发问题:部分员工的薪资变成了null
null -- 空值参与运算引发的结果,空值
和任何值运算结果都返回空。
7.3.2 空值替换函数 专门用来解决空值
问题
ifnull(字段名/列名,如果是空值要
替换的值),假如该字段的值不为空,就使
用该字段本身的值
select first_name , salary *
(1+(ifnull(commission_pct,0)/100))*12
from s_emp;
7.4 起别名
7.4.1 在字段名后面加 as 要命名的名
称
select first_name as '姓名' ,
salary * (1+(ifnull
(commission_pct,0)/100))*12 as '年薪'
from s_emp;
7.4.2在字段名后加空格 要命名的名称
select first_name '姓名' , salary
* (1+(ifnull
(commission_pct,0)/100))*12 '年薪'
from s_emp;
7.4.3 查询出姓名、员工的领导
manager_id,如果是空值使用字符串'老板
'替换
select first_name '员工',ifnull
(manager_id,'老板') '领导'
from s_emp;
7.5 查询出员工的全名
select first_name , last_name
from s_emp;
7.5.1 字符串拼接
concat(字符串1,字符串2,...)
select concat('a','b');
select concat('尼古拉斯','-','赵
四') '艺名';
select concat(first_name , ' ',
last_name) '全名'
from s_emp;
7.6 员工分布在哪些不同的部门
dept_id
select first_name,dept_id
from s_emp;
select dept_id
from s_emp;
部门编号出现重复值,需要去重,去
重使用关键字 distinct
select distinct dept_id
from s_emp;
7.7 有哪些部门和职位
select distinct dept_id,title
from s_emp;
部门编号和职位 联合唯一:两个值
组合起来不能重复
41 Stock Clerk
三原色两两组合起来不能重复
红 黄 蓝
红 黄
红 蓝
黄 蓝
复习:
1 连接数据库:
win R --> cmd -->dos窗口
mysql -u root -p123456
2 连接成功后,查看所有数据库
show databases;
3 使用web01
use web01;
4 查看当前使用的数据库
select database();
5 查看当前数据库下的所有表
show tables;
| Tables_in_web01 |
+-----------------+
| s_dept |
| s_emp |
| s_region |
| s_salgrade |
6 查询语句:
6.1 查询s_emp表中的所有数据
select * from s_emp;
6.2员工姓名、职位、月薪
first_name title salary
select first_name,title,salary
from s_emp;
6.3 给字段起别名
select
first_name '姓名',
title '职位',
salary '月薪'
from s_emp;
6.4 字符串拼接
concat(str1,str2,str3...)
查询出员工的全名
select first_name,last_name
from s_emp;
select
concat(first_name,
' ',last_name) '全名'
from s_emp;
6.5 查询员工的姓名,年薪
select first_name,
salary*12 '年薪'
from s_emp;
select first_name,
salary*12*(1+
ifnull(commission_pct,0)/100)
'年收入'
from s_emp;
6.6 查询有哪些部门
select distinct dept_id
from s_emp;
11月26日:
排序:
语法:order by 字段 排序规则
从小到大 asc 默认值,可以不写 升序
从大到小 desc 降序
1.1 查询出员工的姓名和薪资,按照
月薪从小到排序
select first_name,salary
from s_emp
order by salary;
1.2 查询出员工信息,按照部门编号
升序排序,如果部门相同,按照薪水降序
排序。
select first_name,dept_id,salary
from s_emp
order by dept_id,salary desc;
1.3 查询出员工编号为23的员工的信
息(id,姓名,部门编号,月薪)
select id,first_name,
dept_id,salary
from s_emp
where id = 23 ;
where子句表示条件,
起的作用是过滤数据
1.4 查询出Bela的个人信息
select id,first_name,
dept_id,salary
from s_emp
where first_name = 'Bela';
desc s_emp;
1.5 查询出Mark的月薪
select first_name,salary
from s_emp
where first_name = 'Mark';
1.6 查询出薪资在1500到2000之间的
员工姓名和月薪
salary >=1500 and salary<=2000
select first_name,salary
from s_emp
where salary >= 1500 and
salary <= 2000;
and 并且 几个条件都要满足
or 或者 满足任一条件即可
在...之间 between m and n
[m,n] 表示一个闭区间,
从m到n之间,包含m和n
select first_name,salary
from s_emp
where salary
between 1500 and 2000;
练习:查询部门编号在41到45之间的
员工信息。姓名 部门编号 月薪
select first_name,dept_id,salary
from s_emp
where dept_id between 41 and 45;
select first_name,dept_id,salary
from s_emp
where dept_id >= 41
and dept_id <= 45;
1.7 查询出31,32,33号部门的员工姓
名,部门编号,月薪
select
first_name,dept_id,salary
from s_emp
where dept_id = 31 or
dept_id = 32 or
dept_id = 33;
in 在...里面 满足里面的所有值
in(a,b,c,d,e)
select
first_name,dept_id,salary
from s_emp
where dept_id in(31,32,33);
1.8 查询出名字里面以M的开头的员工
信息
like 像... 做模糊匹配
通配符 % 表示0到多个字符
_ 表示任意一个字符
如果要使用特殊字符,需要进行转
义
\ 转义符 % \% _ \_
M%
select first_name,salary
from s_emp
where first_name like 'M%';
1.9 查询出名字里面包含m的员工信
息 _%m%
select first_name,salary
from s_emp
where first_name like '_%m%';
1.10 找出哪些员工没有提成
commission_pct 提成 字段名
select commission_pct
from s_emp;
结果里面包含数值,null
怎么样判断一个null
select first_name,
commission_pct
from s_emp
where commission_pct = null;
null值不能使用=去判断相等,任何
值和null使用=判断相等返回的结果都是
null.
判断和null相等要使用
is null
判断和null不相等要使用
is not null
正确写法:
select first_name,
commission_pct
from s_emp
where commission_pct is null;
1.11 找出工资大于1500并且有提成
的员工的姓名,部门编号,月薪,提成
select first_name,dept_id,
salary,commission_pct
from s_emp
where salary > 1500 and
commission_pct is not null;
常见的连接词:
肯定形式的 否定形式
in not in
like not like
is null is not null
between and not between and
1.12 查询出42部门的员工的年薪,并
且按照年薪从大到小排序
select
first_name,dept_id,salary*12
from s_emp
where dept_id = 42
order by salary *12 desc;
可以使用别名进行排序--推荐使用
select
first_name 'name',
dept_id '部门编号',
salary*12 'yearsal'
from s_emp
where dept_id = 42
order by yearsal desc;
使用字段的序号进行排序
select
first_name 'name',
dept_id '部门编号',
salary*12 'yearsal'
from s_emp
where dept_id = 42
order by 3 desc;
总结:
select 语句语法
select 字段名 '别名 ',
表达式,函数...
from 表名1 别名1,
表名2 别名2,...
where 子句 条件组合
and or not...
group by 分组字段
having 分组后的过滤条件
order by 字段 排序规则
2 mysql的函数
2.1 单行函数
返回一行结果
2.2 多行函数
多行记录返回一条结果
2.3 字符串处理函数
'abc'
2.3.1 小写函数
lower(字符串)
select lower('Hello World');
2.3.2 大写函数
upper(字符串)
select upper('hello World');
2.3.2 字符串拼接
2.3.2.1 concat
(str1,str2,...);
select concat
('I','Like','Money');
2.3.2.2 拼接的字符串中有空值
,
返回null
select concat
('I','Like',null,'Money');
2.3.2.3 有数值参加拼接,直接
被转换为字符串
select concat
('I','Love','Money',10000000);
opt 代表一个符号
2.3.2.4 concat_ws
(opt,str1,str2,...);
在每个字符串后面加一个分隔符
select concat_ws
(',','I','Like','Money');
2.3.3 求子串 position 位置
substring(str,pos[,len]);
从第二个字符开始到结束
select substring
('abcdefg',2);
第一个字符的数字是1
select substring('中国人民
站起来了',3);
select substring('I love
money $10000000',3,10);
负数表示倒数几个
substring(str,-5);
select substring('I love
money $10000000',-9);
2.3.4 字符串长度 length(字符
串)
select length('abcdefg');
select length('中国');
2.4 输出每个员工的姓名,大写姓名
,小写姓名
select first_name,upper
(first_name),
lower(first_name)
from s_emp;
2.5 找出42号部门每个员工姓名的最
后两个字母
倒序截取
select first_name,substring
(first_name,-2)
from s_emp
where dept_id = 42;
顺序截取 abcdefg
select first_name,substring
(first_name,
length(first_name)-1,2)
from s_emp
where dept_id = 42;
first_name 要截取的
字符串
substring(first_name,
length(first_name)-1,2)
length(first_name) 求得字符
串的长度
length(first_name)-1
字符串的倒数第二
个字符
2 从倒数第二个字符开始截取
两个字符
2.6 mysql的数值处理函数
2.6.1 abs(x) 返回x的绝对值
select abs(-8);
2.6.2 ceil(x) 返回不小于x的最
小整数
select ceil(8.88),ceil(-
8.88);
2.6.3 floor(x);返回不大于x的
整数
select floor(8.88),floor
(-8.88);
2.6.4 mod(x,y) 返回x整除以y的
余数 取余 模
select mod(8,5);
select 8 % 5;
select 8 mod 5;
2.6.5 round(x[,d]) 将数字x四舍
五入到指定的小数位数,如果不指定d的
值,默认是0,如果d的取值是负数,表示
从小数点的左边四舍五入
select round
(1.8888,3),round(1.4);
select round(5.8,-1);
2.6.6 truncate(x,d) 将数字x截断
到指定的小数位数,如果d的取值是负数,
表示从小数点的左边进行截断
select truncate(1.8888,2);
select truncate(1.8888,0);
select truncate(88.8888,-1);
1 mysql -uroot -p123456
2 use web01;
3 show tables;
4 select * from s_emp;
5 select first_name,title,salary
from s_emp;
6 查询出Ben的入职日期 start_date
select first_name,start_date
from s_emp
where first_name = 'Ben';
7 查询出姓名以A开头的人的姓名,月薪
升序排序
select first_name,salary
from s_emp
where first_name like 'A%'
order by salary;
8 查询出 姓名中包含字母y的员工的姓名
月薪 按照月薪降序排序
select first_name,salary
from s_emp
where first_name like '_%y%'
order by salary desc;
9 查询出Henry在哪个部门dept_id工作
select first_name,dept_id
from s_emp
where first_name = 'Henry';
10 查询出Henry在哪个部门(名称)工作
select first_name,dept_id
from s_emp;
select * from s_dept;
select
e.first_name,e.dept_id,
d.id,d.name
from s_emp e,s_dept d
where first_name = 'Henry'
and e.dept_id = d.id ;
标准sql:
内连接 inner join on 连接条件
select
e.first_name,e.dept_id,
d.id,d.name
from s_emp e
inner join s_dept d
on e.dept_id = d.id
and first_name = 'Henry';
表连接:
通过表中字段的关系进行连接,从
而查询完整的数据。
一个表中的字段参照与另外一个表
中的某一个字段时,我们把这种关系叫外
键关系。
s_emp s_dept
dept_id 外键 id primary key
连接的分类:
1 内连接 数据会严格匹配
1.1 等值连接
1.2 非等值连接
1.3 自连接
11 查询部门名称和所在地区名称
s_dept s_region
region_id id
select * from s_region;
select d.name,d.region_id,
r.id,r.name
from s_dept d ,s_region r
where d.region_id = r.id;
标准sql:
select d.name,d.region_id,
r.id,r.name
from s_dept d
inner join s_region r
on d.region_id = r.id;
12 查询出Mark在哪个地区工作
s_emp s_dept s_region
dept_id id region_id id name
select e.first_name,e.dept_id,
d.id,d.region_id,
r.id,r.name
from s_emp e,
s_dept d ,
s_region r
where e.first_name='Mark'
and e.dept_id = d.id and
d.region_id =r.id;
13.查询出员工的姓名、薪水、工资级别
select * from s_salgrade;
| grade | losal | hisal |
+-------+---------+----------+
| 1 | 2000.00 | 10000.00 |
| 2 | 1500.00 | 1999.00 |
| 3 | 1200.00 | 1499.00 |
| 4 | 1000.00 | 1199.00 |
| 5 | 500.00 | 999.00 |
+-------+---------+----------+
select e.first_name,e.salary,
s.losal,s.hisal,s.grade
from s_emp e,s_salgrade s
where e.salary
between s.losal and s.hisal;
标准sql:
select e.first_name,e.salary,
s.losal,s.hisal,s.grade
from s_emp e,s_salgrade s
where
e.salary >= s.losal and
e.salary <= s.hisal;
查询出Mark的工资等级
select e.first_name,e.salary,
s.losal,s.hisal,s.grade
from s_emp e,s_salgrade s
where e.first_name = 'Mark'
and e.salary
between s.losal and s.hisal;
非等值连接:不使用=作为连接条件
> < >= <= != between and in
14 查询出每个员工和领导的姓名
desc s_emp;
select id,first_name , manager_id
from s_emp;
select e.first_name '员工姓名',
e.manager_id,
s.id,s.first_name '领导姓名'
from s_emp e,s_emp s
where e.manager_id = s.id;
标准sql:
15 Carmen 失踪 解决方案:
原因 Carmen的manager_id的值
是null,空值和任何值比较返回
的结果都是null
2 外连接 outer join
它是对内连接的补充,解决记录
丢失的问题
2.1 左外连接
left outer join on
左表的记录一条都不少
2.2 右外连接
右表的记录一条都不少
2.3 全外连接
两边的记录一个都不少
16 查询出每个员工和领导的姓名
select e.first_name '员工姓名',
s.first_name '领导姓名'
from s_emp e
left outer join s_emp s
on e.manager_id = s.id;
17 使用空值替换函数给老板
安排一个领导
select e.first_name '员工姓名',
ifnull(s.first_name,'BOSS')
'领导姓名'
from s_emp e
left outer join s_emp s
on e.manager_id = s.id;
18 建立两张表:
t_dept :
id, int pri
name not null
t_emp:
id int pri
name not null
dept_id
drop table t_dept;
create table t_dept(
id int primary key,
name varchar(20) not null
);
drop table t_emp;
create table t_emp(
id int primary key,
name varchar(20) not null,
dept_id int
references t_dept(id)
);
insert into t_dept
values(11,'Java');
insert into t_dept
values(12,'C++'),
(13,'Python'),
(14,'PHP');
insert into t_emp
values(1,'Tom',11);
insert into t_emp
values(2,'James',12),
(3,'Marry',null),
(4,'Tony',13),
(5,'Ajax',11),
(6,'Nill',12);
commit;
select * from t_dept;
select * from t_emp;
19 查询所有员工和部门信息
dept_id int
references t_dept(id)
参照 t_dept表的id字段
select e.name,d.name
from t_emp e ,t_dept d
where e.dept_id = d.id;
Marry 左外连接
select e.name,d.name
from t_emp e
left outer join t_dept d
on e.dept_id = d.id;
右外连接
select e.name,d.name
from t_emp e
right outer join t_dept d
on e.dept_id = d.id;
全外连接 --mysql不支持
select e.name,d.name
from t_emp e
full outer join t_dept d
on e.dept_id = d.id;
mysql的全外连接
select e.name,d.name
from t_emp e
left outer join t_dept d
on e.dept_id = d.id
union
select e.name,d.name
from t_emp e
right outer join t_dept d
on e.dept_id = d.id;
20 计算提成的平均值 avg()
select avg(commission_pct)
from s_emp;
| avg(commission_pct) |
+---------------------+
| 13.000000 |
+---------------------+
由于分组函数忽略空值
导致平均值过高
要使用空值替换函数
select
avg(ifnull(commission_pct,0))
'提成平均值%'
from s_emp;
21 统计t_emp记录的行数 count()
count()会统计空值
select count(*)
from t_emp;
select count('id')
from t_emp;
select count('dept_id')
from t_emp;
22 统计s_emp记录的行数
select count('manager_id')
from s_emp;
23 统计s_emp表中的部门个数
select count('dept_id')
from s_emp;
去重:
select
count(distinct dept_id)
from s_emp;
24 统计出各个工资级别
有多少个员工
select * from s_salgrade;
select count(e.first_name),
e.salary,s.grade
from s_emp e, s_salgrade s
where e.salary between s.losal
and s.hisal
group by s.grade;
按照 s.grade分组
count(e.first_name)
通过e.first_name来统计每个分组的行数
文章转载自edge的IT空间,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




