MySQL实训2
发布日期:2021-05-12 16:03:11 浏览次数:12 分类:精选文章

本文共 3634 字,大约阅读时间需要 12 分钟。

MySQL������������

Step 1: ���������������

������MySQL������������������������������������

mysql -u root -p

���������������yi���

create database yi;

Step 2: ������������������

  • ������������employee������������������������������
  • create table employee(    empid varchar(10) primary key not null,    name varchar(10),    gender varchar(10),    title varchar(20),    birthday date,    depid varchar(10));

    ������������������

    desc employee;
    1. ������������department���
      ���������������������������
    2. create table department(    depid varchar(10) primary key not null,    depname varchar(20));

      ������������������

      desc department;
      1. ������������salary���
        ���������������������������
      2. create table salary(    empid varchar(10) primary key not null,    base_salary decimal(8,2),    title_salary decimal(8,2),    deduction int);

        ������������������

        desc salary;

        Step 3: ���������������

        ������������������������������������������������

        alter table employee add column department_profile varchar(100);

        ������������������

        desc employee;

        Step 4: ������������

      3. ���������������
      4. insert into employee values     ('1001', '������', '���', '���������������', '1980-01-01', '1111', null),    ('1002', '������', '���', '���������������', '1980-01-01', '1111', null),    ('1003', '������', '���', '���������', '1980-01-21', '2222', null),    ('1004', '������', '���', '���������', '1980-01-11', '2222', null);

        ���������������

        select * from employee;
        1. ���������������
        2. insert into department values    ('1111', '���������'),    ('2222', '���������'),    ('3333', '���������');

          ���������������

          select * from department;
          1. ���������������
          2. insert into salary values    ('1001', 3200, 1200, 200),    ('1002', 4200, 1100, 100),    ('1003', 5200, 2200, 200),    ('1004', 2000, 1500, 150);

            ���������������

            select * from salary;

            Step 5: ������������

            ���������������������������������������������������������������

          3. ���������������
          4. update employee set title = '���������' where name = '������';
            1. ���������������������������������������������
            2. select empid from employee where name = '������'; -- ������������empid���1002update salary set base_salary = 5700, title_salary = 600 where empid = '1002';

              ������������������������

              select * from employee;select * from salary;

              Step 6: ������������

            3. ������������������������������������
            4. select employee.empid, name, title, depname,     (base_salary + title_salary - deduction) as ������������,    (base_salary + title_salary) as ������������from employee left join salary on employee.empid = salary.empidleft join department on department.depid = employee.depid;

              ���������������

              select * from employee;
              1. ���������������������������������45���������������
              2. select * from employee where name like '���%' and (year(curdate()) - year(birthday)) < 40;

                ���������������

                select * from employee where name like '���%';
                1. ������������������������������������
                2. select employee.empid, name, title, depname, (base_salary + title_salary - deduction) as ������������from employee left join salary on employee.empid = salary.empidleft join department on department.depid = employee.depidwhere depname = '���������';

                  ���������������

                  select * from department;

                  Step 7: ������������

                3. ������������������������
                4. select title, count(*) as ������ from employee group by title;

                  ���������������

                  select * from employee;
                  1. ������������������������������������������
                  2. select depname, sum(base_salary + title_salary - deduction) as ������������,    avg(base_salary + title_salary - deduction) as ������������from employee left join salary on employee.empid = salary.empidleft join department on department.depid = employee.depidgroup by depname;

                    ���������������

                    select * from department;
    上一篇:MySQL实训3
    下一篇:MySQL实训1

    发表评论

    最新留言

    网站不错 人气很旺了 加油
    [***.192.178.218]2025年04月05日 02时52分55秒