sql入门

作者: DouDouZH | 来源:发表于2017-09-22 18:59 被阅读0次
创建名字叫做mydb的数据库:

create database mydb;

选择数据库名:

use mydb;

删除数据库:

drop database mydb;

查看数据库:

show databases;

创建表:

create table student(
姓名 varchar(10),
性别 varchar(2) ,
出生日期 date,
收入 int(6));

查表:

show tables;

显示表结构:

show columns mydb;

插入一行数据:

insert into student(姓名,性别) values('张三','男');

修改数据:

update student set 性别='女' where name='张三';

删除记录:

delete form student 删除所有记录;
delete from student where 姓名='张三';

清除数据:

truncate table student;

查询:

select * from student;查询全部
select 姓名 from student where 性别='男';按条件查询需要字段
select 姓名 from student where 姓名 like '%张%';查询名字带张的人姓名
select 姓名 from student where 姓名 like '张__';查询张某某的名字
select distinct 姓名 from student; 查询名字不同的,相同的合并
select max(工资) as 最大,min(工资) as 最小,avg(工资) as 平均 from student;
select count(*) as 人数 from student;查询总人数
select year(now())-year(出生日期) as 年龄 from student;
select zgxx.姓名,出生日期,工资,奖金 from gz,zgxx where gz.职工号=zgxx.职工号 and 性别='女';链接查询

相关文章

网友评论

      本文标题:sql入门

      本文链接:https://www.haomeiwen.com/subject/mrgfextx.html