创建数据库:create datebase S;
查看数据库:show databases;
删除数据库:Drop database S;
调用数据库:use S;
创建表:create table S(表单名 char(10)primary key,scmc char(12));
创建表只包含“test”,int:create table S,(test int);
查表:desc S;select datebase();
显示创建的表:describe S;
添加数据insert into chaoshi120 values(‘XXX’,‘XXX’,‘XXX’);
表中增加字段:alter table S add TEL char(11);
修改字段数据类型:alter table S modify xy varchar(20);
修改字段名:alter table S change XY ZY varchar(20);
删除字段:alter table S drop TEL;
改字段位置:alter table C modify xs int after xf;
表改名:alter table S rename to SC
删除表:create table AA,drop table AA;
显示所有表:show tables;
显示表结构:show create table S;
查S表中的所有信息:select*from S;
查S表中的指定信息:select 信息的名字 from S where 表中的项目名=‘XXX’;
查S表中的xm xh zy :select xm,xh,zy from S;
除重复查询:select distinct jg from S;
查S中的xm和nl:select xm,year(now())-year(csrq) asnl from S;
查姓王的xm:select xm from S where xm like ‘王%’;
表里强改:update S set xh=82837;
升降序按性别统计S男女人数:select xb ,count(xb)from Sgroup by xb;
查S的xm和csrq升序:select cm csrq from older by csrq asc;查S表的kcm按照课程名称显示:select kcm as 课程名称 from S;
查S中关于数据记录:select * from S where kcm like “%数据%” or kcm like “%程序%”;
查课S表的程门数:select count(kcm) as 课程门数 from S;
查询C表中各门课程的总学分。结果列用别名‘总学分’表示。Select sum(xf) as总学分from c;
查询sc 表中成绩不及格(即cj < 60)的所有记录
select cj from sc where cj < 60;
查询sc 表中cj为null的记录:select * from sc where cj is null;
查询sc 表中选修了“101”或“245”课程的xh,kch和cj三列数据。select * from sc where kch = ‘101’ or kch = ‘245’;
查询SC表中选修了kch为‘245’课程的最高分、最低分、平均分,并以相应的中文别名显示。
select max(cj) as 最高分 from sc where kch = 245;
select min(cj) as 最低分 from sc where kch = 245;
select avg(cj) as 平均分 from sc where kch = 245;
计算sc表中每门课的平均分。(用group by分组子句)select kch, avg(cj)from scgroup by kch;
计算sc表中每个学生各门课的平均分。(用group by分组子句)select xh, avg(cj)from scgroup by xh;
查询sc表,先按xh的升序排列,xh相同者再按cj的降序排列。Select * from sc order by’xh’ asc;
初学向--MySQL数据库基本操作
最新推荐文章于 2025-02-11 18:17:37 发布