MYSQL简单应用

1.建立一个数据库

create database vfast;
2.新建一个用户表
create table employee(employee_id int,name char(12),gerder enum('M','F'),dent_id set("1","2","3","4"),join_time date,salary float,phone char(11),address char(40),description text);
3.建立用户记录
insert into tablename values(1,"name","F/M","1/2/3/4","2000-01-01",1234.56,"13800000001","address","description")
4.实现sql查询
    按名字查找
    select * from tablename where name="employeename";
    按照薪水>查找
    select * from tablename where salary>4300 and salary<9000;
    查找每个部门的人数
    select dent_id,count(*) as dentsum from tablename group by dent_id;
    每个部门的平均薪资
    select dent_id,avg(salary) as avgsalary from tablename group by dent_id;
    描述字段为空的员工
    select * from tablename where description is null;
    求出每个部 门女员工工资最高的职工的薪水
    select max(salary) from tablename where gerder='F' group by dent_id;
    名字以l开头的员工个数
    select * from tablename where name like "l%"

你可能感兴趣的:(mysql)