18---sql 语句

 

1.       创建数据库
./usr/local/mysql/bin/mysql
Show databases;
Create database rx;
2.       创建表
Use rx;
Create yg.rx (employee_id int,name char(10), gender enum(‘M’,’W’), dept_id set (1,2,3,4), join_time date, salary int, phone int, address char(10), description char(10));
 ##查看创建表
Desc yg;
3.       向表中添加数据
Insert  into yg values(1,”xingxing”,’M’,’1’, ‘2010-12-16’, 2500,138350,’beijing’, ‘yg’);
4.       表中数据出错的修改方式
Update yg set employee_id=8 where name=’xingxing’;
##列属性的修改
Alter table yg modify address char(20);
5.       查询表中某个人的记录
Select * from yg where name=”xingxing”;
6.       按薪水查找大于3000的
Select name,salary>=3000 from yg;
Select * from yg where salary>=3000;
7.       每个部门有多少人
4个部门:
Select count(*) from yg group by dept_id;
每个部门;
Select count(*) from yg group by dept_id having dept_id=’2’;
8.       每个部门的平均工资
Select avg(salary) from yg group by dept_id;
Select avg(salary) from yg group by dept_id having dept_id=’1’;
9.       是否有人描述字符为空
##添加空字符的描述
Insert into yg values();
Insert into yg values(10,”niy”, ’M’, ’1’, ”2003-12-10”,1223,138,null,null);
Select * from yg where name is null;
10.   每个部门赚的最多的人
Select name,mix(salary) from yg group by debt_id;
Select name,mix(salary) from yg group by debt_id having debt_id=’1’;
11.   名字是以l 开头
Select name from yg where name like ”l%”;
 
 
 

你可能感兴趣的:(sql,语句)