爱美容
当前位置: 首页 美容百科

简单sql语句大全(常用sql语句)

时间:2023-06-17 作者: 小编 阅读量: 1 栏目名: 美容百科

三张表学生信息、课程表、分数表创表语句--学生信息createtablet0_student(studentidvarchar(10),classidvarchar(10),namevarchar(20),sexvarchar(1));commentoncolumnt0_student.studentidis'学生编码';commentoncolumnt0_student.classidis'学生

三张表 学生信息、 课程表、分数表

创表语句

-- 学生信息

create table t0_student

(

studentid varchar(10),

classid varchar(10),

name varchar(20),

sex varchar(1)

);

comment on column t0_student.studentid is '学生编码';

comment on column t0_student.classid is '学生班级 1 班级1 ,2 班级2';

comment on column t0_student.name is '学生姓名';

comment on column t0_student.sex is '学生性别,1 男,2 女';

alter table t0_student add constraint pk_t0_student primary key (studentid,classid)

-- 课程表

create table to_course

(

courseid varchar(10),

coursename varchar(10)

);

comment on column to_course.courseid is '课程编码,1,2,3,4,5';

comment on column to_course.coursename is '课程名称 1英语,2语文,3数学,4物理,5化学';

alter table to_course add constraint pk_to_course primary key (courseid);

-- 分数表

create table to_score

(

courseid varchar(10),

classid varchar(10),

studentid varchar(10),

score number

);

comment on column to_score.courseid is '课程编码';

comment on column to_score.classid is '班级编码';

comment on column to_score.studentid is '学生编码';

comment on column to_score.score is '分数';

alter table to_score add constraint pk_to_score primary key (courseid,classid,studentid);

insert into t0_student values('1','1','张三','1');

insert into t0_student values('2','1','李四','2');

insert into t0_student values('3','1','王五','1');

insert into t0_student values('4','1','赵六','2');

insert into t0_student values('5','2','张三','1');

insert into t0_student values('6','2','李四','2');

insert into t0_student values('7','2','王五','1');

insert into t0_student values('8','2','赵六','2');

insert into t0_student values('9','1','jackMa','1');

insert into to_course values('1','英语');

insert into to_course values('2','语文');

insert into to_course values('3','数学');

insert into to_course values('4','物理');

insert into to_course values('5','化学');

insert into to_score values('1','1','1',50);

insert into to_score values('1','2','1',70);

insert into to_score values('2','1','2',100);

insert into to_score values('2','2','2',100);

insert into to_score values('3','1','3',90);

insert into to_score values('3','2','1',70);

insert into to_score values('4','1','4',80);

insert into to_score values('4','2','1',60);

insert into to_score values('5','1','4',90);

insert into to_score values('4','2','5',80);

insert into to_score values('3','2','5',80);

insert into to_score values('2','2','5',80);

insert into to_score values('1','2','5',80);

insert into to_score values('5','2','6',75);

insert into to_score values('4','2','6',60);

insert into to_score values('3','2','6',60);

insert into to_score values('2','2','6',60);

insert into to_score values('1','2','6',90);

/****************************************************************************sql 语句 ****************************************************************************/

--- 2班张三分数列表

select student.name, decode(student.sex,'1','男','2','女') sex,course.coursename,score.score

from to_score score, t0_student student, to_course course

where student.studentid='5' and student.classid='2'

and score.courseid = course.courseid

and student.studentid = score.studentid

and student.classid = score.classid

--- 2班 成绩行转列方式展示

with t as(

select student.name, decode(student.sex,'1','男','2','女') sex,course.coursename,score.score

from to_score score, t0_student student, to_course course

where score.courseid = course.courseid

and student.studentid = score.studentid

and student.classid = score.classid and student.classid='2' )

select * from(select * from t

)

pivot (sum(score) for coursename in ('英语','语文','数学','物理','化学'));

--- 查询分数大于80分 的人数

select count(distinct studentid) from to_score

where score>80

--查询有两科成绩大于 80分记录数

select studentid,score,count(*) from to_score

where score>=80

group by studentid,score

having count(*)>2

--- 查询所有的英语成绩 按成绩 由高往低排序

select * from to_score where courseid ='1' order by score desc

-- 查询 所有后英语成绩的总分,最高分,最低分,平均分(保留两位小数)

select sum(score) 总分,max(score) 最高分,min(score) 最低分,round(sum(score)/count(*),2) 平均分 from to_score where courseid ='1'

-- 查询所有成绩 优秀人数 (>=90),良好人数(80-90),及格人数(60-80), 不及格人数(<60)

select suM(case

when score>=90 then 1

else 0 end ) 优秀人数,

suM( case

when score >=80 and score<90 then 1

when score >=60 and score<80 then 1

else 0 end) 良好人数,

suM(case

when score >=60 and score<80 then 1

else 0 end) 及格人数,

suM( case

when score <60 then 1

else 0 end) 不及格人数

from to_score

---查询90分以上各分数人数。rollup 统计总人次

select score ,count(*) from to_score where score >=90 group by rollup(score)

--- 删除名字重复的 学生 (如果没有studentid 这样的主键列的时候 可以通过rownum 增加一个虚拟列然后再删除)

delete t0_student

where studentid in(select studentid from (

select max(studentid) studentid ,name from t0_student group by name ))

--查询为非汉字的学生名字

select * from t0_student where asciistr(name) not like '%\%';

--随机抽取成绩中10% 数据

select * from to_score sample block(10);

    推荐阅读
  • 怎么样让眼睛变大的最有效的方法(5种方法让你的眼睛变大)

    使用时先轻刷一层睫毛膏,趁睫毛膏尚未干掉时,将增长纤维的刷头转出,并将刷头上的白色细致纤维轻轻以滚动方式附着每根睫毛的尖端部位。再重复刷上黑头睫毛膏,电眼效果max。

  • 双减带给老师的挑战和机遇(双减之后教师面临的)

    7月24日,中共中央办公厅、国务院办公厅印发了《关于进一步减轻义务教育阶段学生作业负担和校外培训负担的意见》。面对教师陡然增加的负担,教育部相关负责人回应,将继续督促指导各地将教师减负工作同优化教师资源配置、深化教育教学改革等有机结合起来,健全教师减负长效机制,推动教师减负工作取得实效。“双减”政策明确提出,要构建教育良好生态,有效缓解家长焦虑情绪,促进学生全面发展、健康成长。

  • 我的世界橡胶甘蔗怎么杂交 我的世界粘性甘蔗种子

    杂交前需要合成作物架,用4个木棍合成,摆放成左右两列,合成2个作物架,由于杂交的几率比较低,所以需要准备多点作物架。拿着作物架在,每两个种了甘蔗的耕地的中间,放上两个作物架,作物架成十字交叉,代表此时在进行杂交。进行一段长时间的等待,等待甘蔗长大,等待杂交成功,注意杂交的地方很容易长杂草,如果长了杂草请尽快打掉,否则整个耕地都会蔓延杂草,需要重新杂交。

  • 娃哈哈新媒体营销策划(第13届娃哈哈营销策划大赛重磅来袭)

    为了丰富大学生的课余生活,引导和培养大学生创新精神和实践能力,4月23日18时30分,第十三届娃哈哈全国大学生营销策划大赛启动仪式于南宁职业技术学院大礼堂顺利举行。娃哈哈营销大赛为大学生提供了一个广阔的实践平台,推动教育与实践相结合,使同学们的创新意识得到激发。在此预祝娃哈哈营销策划大赛取得圆满成功,也祝本次参赛的团队都能够在比赛中取得佳绩!

  • 狮鹫怎么驯服(方舟生存进化手游狮鹫驯服技巧攻略)

    接下来我们就一起去研究一下吧!狮鹫怎么驯服方舟生存进化中狮鹫是高傲的守护兽,想要驯服狮鹫并不容易,必须获得狮鹫的尊重,这并不算容易的事,下面就来介绍一下怎么驯服狮鹫的方法吧。第一种方法:人物等级85级以上,并且不是可以获得全部尊重的!比如85级的,可能只能获取低等级狮鹫的尊重!

  • tabata间歇性训练的方法(什么是Tabata锻炼)

    各种研究得出结论,Tabata锻炼对健康有很多好处。有时您可能会达到最大强度,这可能会因肌肉松懈而导致受伤每周最多进行3-4次Tabata训练。Tabata锻炼以多种方式改善健康。此外,心脏病患者在开始Tabata锻炼之前还应听取医生的建议。在没有科学证据的情况下,对原始Tabata版本的修改可能弊大于利。人们可能会选择Tabata只是为了减肥,这不是它的实际用途。与传统HIIT相比,Tabata的强度水平更高,恢复时间更短。

  • s10和s9有什么区别(s10和s9有什么区别瑞思迈)

    vivoS9电池容量4000mAh,配置33W闪充。vivo官方宣布vivoS10系列于2021年7月15日正式发布,该手机代言人有Lisa、蔡徐坤、刘昊然。2021年7月15日,vivo召开了S10系列发布会,会上发布了新一代自拍旗舰vivoS10系列,其vivoS10系列依然采用了前置4400万像素AF双摄设计,仍然支持105度超广角,还有前置微缝式双柔光灯。

  • 专业版微博怎么设置(其实很简单)

    接下来我们就一起去了解一下吧!专业版微博怎么设置需要认证过才能成为专业版。专业版微博是为企业和机构定制的微博。新浪微博企业版是我们为企业、机构用户量身打造的服务平台。它具有更丰富的个性化页面展示功能设置,更精准的数据分析服务,以及更高效的沟通管理后台。我们期待新浪微博企业版能够帮助企业更便捷地与目标用户进行互动沟通,提升营销效果转化,挖掘更多商业机会。

  • 变速箱油到底多久换一次呢(变速箱油多久更换一次)

    如果需要更换变速箱油,查看用户的保养手册上如果有明确的更换周期,按照规定换油。如果变速箱油是终身免维护的,也一样要引起重视,终身免维护并不意味着变速箱油一直不用换。其实变速箱油不像机油那么黑,相比于机油甚至更为干净一点。所以车主千万不要忽略变速箱油,如果过长时间不更换,也会对变速箱造成一定的损伤,而且一些汽车的变速箱比发动机还要昂贵,修一次可能得要好几万元。

  • 恐惧症会遗传吗 幽闭恐惧症会遗传吗

    恐惧症是发病率非常高的一种心理疾病,而有许多患者并没有得到有效的治疗。导致恐惧症的因素恐惧症是各种因素的共同作用。恐惧症的典型症状是恐怖发作,并伴有强烈的生理反应。尽管患者知道这种恐惧是不合理的,但是没法控制。研究表明,在100名患者中40名患者可以彻底治疗,基本上没有什么后遗症。所以一定要及早治疗,效果好,造成的危害也小。