




免费预览已结束,剩余3页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1. sqlgroup by2005-05-09 2005-05-09 2005-05-09 2005-05-09 2005-05-10 2005-05-10 2005-05-10 , sql? 2005-05-09 2 22005-05-10 1 2-create table #tmp(rq varchar(10),shengfu nchar(1)insert into #tmp values(2005-05-09,)insert into #tmp values(2005-05-09,)insert into #tmp values(2005-05-09,)insert into #tmp values(2005-05-09,)insert into #tmp values(2005-05-10,)insert into #tmp values(2005-05-10,)insert into #tmp values(2005-05-10,)1) select rq, sum(case when shengfu= then 1 else 0 end),sum(case when shengfu= then 1 else 0 end) from #tmpgroup by rq2) select n.rq,n.,m.“ from (select rq,=count(*) from #tmp where shengfu=group by rq)n inner join (select rq,“=count(*) from #tmp where shengfu=group by rq)m on n.rq=m.rq3) select a.rq,a.a1 ,b.b1 from (select rq,count(rq) a1 from #tmp whereshengfu= group by rq) a,(select rq,count(rq) b1 from #tmp where shengfu= group by rq) b where a.rq=b.rq2.sqla b c,sqlababbcbc-create table #tmp(a int,b int,c int)insert into #tmp values(10,20,30)-insert into #tmp values(10,30,20)-insert into #tmp values(40,10,20)select * from #tmpselect (case when a>b then a else b end),(case when b>c then b else c end ) from #tmp3.sqltb_send(sendtime)?(sendtimedatetime)-select * from #tmp where datediff(dd,rq,getdate()=0select * from #tmp where rq=rtrim(convert(varchar,getdate(),23)4.33708058sql806060 -create table #tmp( int, int , int)insert into #tmp values(70,80,58)-insert into #tmp values(100,50,60)select * from #tmpselect (case when >=80 then when >=60 then else end ) ,(case when >=80 then when >=60 then else end ) ,(case when >=80 then when >=60 then else end ) from #tmp5.sqlserver2000sqlididvalues,int?-:create table #xx(id int, idvalues int):create table #xx(id int, idvalues int):session,.sql server,session,.6.sqlserver2000-(*.dbf),sql server.sql server 2000 .mdf .ndf .ldf7.sqltable1,table2table3table1mon dep yj-01100210035028049038table2depdname-01020304table3 resultdep -0110 nullnull02108 null03null 5 804nullnull9-create table #a(mon varchar(10),dep varchar(10) ,yj int)insert into #a values(,01,10)insert into #a values(,02,10)insert into #a values(,03,5)insert into #a values(,02,8)insert into #a values(,04,9)insert into #a values(,03,8)select * from #acreate table #b(dep varchar(10),dname varchar(20)insert into #b values(01,)insert into #b values(02,)insert into #b values(03,)insert into #b values(04,)select * from #b-1) select dep,(select sum(yj) from #a where mon= and #a.dep=#b.dep) ,(select sum(yj) from #a where mon= and #a.dep=#b.dep) ,(select sum(yj) from #a where mon= and #a.dep=#b.dep) from #b2) select b.dep,dname,sum(case when a.mon= then a.yj else 0 end ) as ,sqlsql1student(s#,sname,sage,ssex) course(c#,cname,t#) sc(s#,c#,score) teacher(t#,tname) 1001002selecta.s#from (select s#,score from sc where c#=001) a,(select s#,score from sc where c#=002) bwherea.score>b.score and a.s#=b.s#;260select s#,avg(score)fromscgroup by s# having avg(score) >60;3select student.s#,student.sname,count(sc.c#),sum(score)from student left outer join sc on student.s#=sc.s#group by student.s#,sname4select count(distinct(tname)from teacherwhere tname like %;5select student.s#,student.snamefrom studentwhere s# not in (select distinct( sc.s#) from sc,course,teacher where sc.c#=course.c# and teacher.t#=course.t# and teacher.tname=);6001002select student.s#,student.snamefromstudent,scwhere student.s#=sc.s# and sc.c#=001and exists( select * from sc as sc_2 where sc_2.s#=sc.s# and sc_2.c#=002);7select s#,snamefrom studentwhere s# in(select s#from sc ,course ,teacherwhere sc.c#=course.c# and teacher.t#=course.t# and teacher.tname= group by s# having count(sc.c#)=(select count(c#) from course,teacher where teacher.t#=course.t# and tname=);860select s#,snamefrom studentwhere s# not in (select student.s# from student,sc where s.s#=sc.s# and score>60);9select student.s#,student.snamefromstudent,scwherestudent.s#=sc.s#group by student.s#,student.sname having count(c#) <(select count(c#) from course);101001 select s#,snamefromstudent,scwhere student.s#=sc.s# and c# in select c# from sc where s#=1001;11scdelect scfrom course ,teacherwhere course.c#=sc.c# and course.t#= teacher.t# and tname=;from sc l ,sc rwhere l.c# = r.c#andl.score = (select max(il.score)from sc il,student imwhere il.c# = l.c# and im.s#=il.s#group by il.c#)andr.score = (select min(ir.score)from sc irwhere ir.c# = r.c#group by ir.c# );13select 1+(select count( distinct )from (select s#,avg(score) from scgroup by s# ) t1where > t2.) , s# ,from (select s#,avg(score) from sc group by s# ) t2order by desc;14:()select t1.s# as id,t1.c# as id,score as from sc t1where score in (select top 3 scorefrom scwhere t1.c#= c#order by score desc)order by t1.c#;15select t1.s# as id,t1.c# as id,score as from sc t1where score in (select top 2 scorefrom scwhere t1.c#= c#order by score desc )order by t1.c#;year salary2000 10002001 20002002 30002003 4000selectb.year,sum(a.salary)from salary a,salary bwherea.year<=b.yeargroup by b.yearorder by b.year;sqla(id,name)3140idselect top 10 *from awhere id >(select max(id) from (select top 30 id from a order by id ) t) order by idselect top 10 *from awhere id not in (select top 30 id from a order by id)order by id2sql431106315student ()course ()sc ()1sql32sql33sql591sqlselectstu.sno, stu.sname from student stuwhere (select count(*) from sc where sno=stu.sno and cno =(select cno from course where cname=) != 0;2sqlselectcname from coursewherecno in ( select cno from sc where sno =(select sno from student where sname=);3sqlselectstu.sno, stu.sname from student stuwhere (select count(*) from sc where sno=stu.sno) = 5;107,s,c,sc,sc12sql,3sql,51mysqlcreate table s(id integer primary key, name varchar(20);create table c(id integer primary key, name varchar(20);create table sc(sid integer references s(id),cid integer references c(id),primary key(sid,cid);2sqlselect stu.id, from s stuwhere (select count(*) from sc where sid=stu.id) = (select count(*) from c);3sqlselect stu.id, from s stuwhere (select count(*) from sc where sid=stu.id)>=5; 108(test)id name age manager(id)106 a 30 104109 b 19 104104 c 20 111107 d 35 109112 e 25 120119 f 45 null:id? sqlselect from test employeewhereemployee.age> (select manager.age from test manager where manager.id=employee.manager);109citystatecityno cityname statenobj nullsh nullgz gd dl ln state no state namegd ln sd nmg city no city name state no state namebj nullnulldl ln gz gd sh nullnullsqlsqlselect c.cityno, c.cityname, c.stateno, s.statename from city c, state swhere c.stateno=s.stateno(+)order by(c.cityno);sql1. sqlgroup by2005-05-09 2005-05-09 2005-05-09 2005-05-09 2005-05-10 2005-05-10 2005-05-10 , sql? 2005-05-09 2 22005-05-10 1 2-create table #tmp(rq varchar(10),shengfu nchar(1)insert into #tmp values(2005-05-09,)insert into #tmp values(2005-05-09,) insert into #tmp values(2005-05-09,) insert into #tmp values(2005-05-09,) insert into #tmp values(2005-05-10,) insert into #tmp values(2005-05-10,) insert into #tmp values(2005-05-10,)1) select rq, sum(case when shengfu= then 1 else 0 end),sum(case when shengfu= then 1 else 0 end) from #tmpgr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 车牌识别维修合同6篇
- 广东省广州市2024-2025学年八年级上学期10月月考英语试卷(含音频)
- 2025-2026学年广东省潮州市潮安区凤塘镇凤和中学八年级(上)第一次月考历史试卷(含答案)
- 手帐本课件教学课件
- 碳捕集技术在纺织领域应用-洞察及研究
- 手划课件制作
- 中裕安全考试题库及答案
- 运输考试题及答案
- 2025年CAAC执照理论复习考试题库
- 2025年房地产金融风险防控与房地产金融市场风险管理框架研究
- 2025年省盐业投资控股集团有限公司招聘笔试备考试题带答案详解
- 电信国庆活动方案
- 市场仿真花施工方案
- 2025年入团知识考试题库(含答案)
- 职业培训项目实施方案
- 蔬菜抗营养成分流失工艺考核试卷及答案
- 破产重整程序中金融债权人保护问题研究
- 柴油发电机施工安装技术方案详述
- 民警培训安全驾驶简报课件
- 十年(2016-2025)高考生物真题分类汇编(全国通.用)专题10 基因的自由组合定律(解析版)
- 2025年大数据应用工程师认证考试预测题详解与实战指南手册
评论
0/150
提交评论