首页 > 数据库技术 > 详细

SQL补充

时间:2020-07-30 19:15:36      阅读:70      评论:0      收藏:0      [点我收藏+]

SQL查漏补缺

1.基本语句

创建 create table 表名(int check(限制数值范围),decimal(精确,小数点位), primary key(),foreign key(外键 reference主键表(列名)))

插入语句insert into table(字段) value(值)

更新语句update table set col=‘’ where

删除语句delete from

视图create view 视图名 as select 

exists 检查返回外表是否有匹配的内表数据 

concat合并两个单元格

cast(字段 as 格式)

 

2.扩展

语文数学英语三科分数均超过80份的名字

select name from s where score>=80
group by name having count(name)=3

select name from s
group by name having min(score)>=80

 

行列互换

年         季度        销售量
1991       1             11
1991       2             12
1991       3             13
1991       4             14
1992       1              21
1992       2              22
1992       3              23
1992       4              24

select year,
sum(case when month=‘1‘ then amount else 0 end) m1,
sum(case when month=‘2‘ then amount else 0 end) m2
from y
group by year

 

删除自动编号不同但其他信息相同的内容

id 号 学号 姓名 课程编号 课程名称 分数
1 2005001 张三 0001 数学 69
2 2005002 李四 0001 数学 89
3 2005001 张三 0001 数学 69

delete from student2 where id not in(select mid from (select min(id) mid
from student2 group by name) as t);

 

区间统计

select kechen,
(case when score>=80 then ‘优秀‘
when score>=60 then ‘及格‘
when score<60 then ‘不及格‘ END)
from s
group by kechen

 

SQL补充

原文:https://www.cnblogs.com/ybxw/p/13404077.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!