SQL_常用关键字

查询语句 

 关键字:SELECT 

查询所有: 

Select * from 表名
Select * from stuInfo 
 查询部分字段 
Select 字段1,字段2,字段3… from 表名 Select stuName,stuSex from stuInfo  
  
插入语句 
关键字:insert  
插入语句: 
insert into 表名  (字段1,字段2…) Values  (值1,值2…)   
 
更新语句 
关键字:update 
更新语句: 
update 表名 Set  字段1=‘值1’,字段2=‘值2’Where  字段3=‘值3’      
 
删除语句 
关键字:delete 
删除语句: 
Delete  *  From  表名 where  字段1=‘值1’    
 
去重复行 
关键字:DISTINCT  
去重复行: 
select distinct 列名1 from 表名 
select distinct depart from teacher 
注意:DISTINCT必须放在所有列名前面   
 
重命名语句 
关键字:AS  
  select  Sno as '学号',  Sname as '姓名',  Ssex as '性别', Sbirthday as'出生日期', Class as'班号'  from  student    
 
区间语句 
关键字:between  
Select  * from  score  where  degree between 60 and 80    
 
指定条件语句 
关键字:IN  
select   *  from  score  where  degree in (85,86,88)    
 
 
AND语句 
关键字:AND 
 select  *  from   score  where   degree>=60 and degree<=80   
 
OR语句 
关键字:OR  
Select  *  from  student  where  class='95031' or  Ssex='女'    
 
排序语句 
关键字:order by 
题目:以Class降序查询Student表的所有记录
 select *  from  student  order by  class desc  
注: 
ASC为升序 默认不写; DESC为降序   
 
汇总语句 
关键字:count(*) 
题目:查询“95031”班的学生人数。
 select count(*) as CNT  from  student  where  class='95031';   
 
求一列的最大值 
关键字:max 
题目:查询Score表中的最高分
select  max(degree)  From Score  
 
求一列的最小值 
关键字:min 
题目:查询Score表中的最低分 
select  min(degree)  From  score   
 
求平均值 
关键字:avg(字段名) 
题目:查询‘3-105’号课程的平均分。
 select  avg(degree) as 课程平均分  from  score  where cno='3-105';   
 
分组语句(having是条件) 
关键字:group by(字段名) having 条件 
题目:查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
Select  cno,  avg(degree)  from  score  where  cno like'3%'  group by  cno  having  count(*) >5; 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值