SQL基本查询语句

查找student表中所有内容
select * from student;
使用distinct去除学号中所有重复的学号即去除重复值
select distinct xuehao from student;
使用where查找成绩表中所有数学成绩等于85分的成绩
select * from chengji where shuxue=85; 

如果查询条件是字符则需要用单引号引起来
例:
查找姓名是于康龙的记录

select *from chengji where name = '于康龙';

以下运算符可以在where字句中使用

= 等于
<> 不等于。注释:在 SQL 的一些版本中,该操作符可被写成 !=
> 大于
< 小于
>= 大于等于
<= 小于等于
BETWEEN 在某个范围内
LIKE 搜索某种模式
IN 指定针对某个列的多个可能值
AND&OR运算

在成绩表中查找男生数学成绩大于90分的记录

select * from chengji where xingbie = '男' and shuxue > 90;
order by desc

若有desc则为降序
将成绩表中按数学成绩从高到底排序

select * from chengji 
order by shuxue;
order by多列排序

将学生表中按性别和成绩进行排序

select *from chengji 
order by xingbie , shuxue;
insert into 插入

向成绩表中加入完整的数据

insert into chengji 
vakues('于康龙',32,64,89);

只向成绩表中加入姓名和数学成绩

insert into chengji (name,shuxue)
value('王五',44);
up date 更新

在成绩表中将于康龙的语文成绩改为11,数学成绩改为22

update chengji
set '语文'=11,'数学'=22
where name ='于康龙';

如果在以上过程中将where省略,则整个表中的语文和数学成绩都被改为11和22

delect 删除

在成绩表中删除姓名为于康龙并且性别为女的记录

delede from chengji
where name = ‘于康龙‘ and 性别 =’女‘;

posted @ 2022-07-20 18:51  于康龙  阅读(189)  评论(0)    收藏  举报