易截截图软件、单文件、免安装、纯绿色、仅160KB

测试一下自己的SQL水平

 
create table Student(Sname varchar(10),Ssex varchar(5),Sage int,S# int)
insert into Student
select '夏亮','男','21','1004'
select '成平','男','20','1001' union all
select '王波','男','19','1002' union all
select '突然','女','19','1003'
 
create table Course(C# varchar(10),Cname varchar(10),T# varchar(10))
insert into Course
select '006','化学','C06' union all
select '005','数学','C06' union all
select '004','地理','C05' union all
select '001','自然','C02' union all
select '002','社会','C01' union all
select '003','心理','C03'
 
 
IF EXISTS (SELECT 1 from SC)
    DROP TABLE SC
GO
create table SC(S# int,C# varchar(10),score int)
insert into SC
select '1004','002',13 union all
select '1004','004',13 union all
select '1004','005',13 union all
select '1004','006',13 union all
select '1004','001',13 union all
select '1004','003',35 union all
select '1003','002',95 union all
select '1003','001',55 union all
select '1001','006',55 union all
select '1001','005',100 union all
select '1001','001',100 union all
select '1002','001',null union all
select '1001','002',90 union all
select '1003','003',68
 
create table Teacher(T# varchar(10),Tname varchar(10))
insert into Teacher
select 'C04','天里浩'union all
select 'C05','天任浩'union all
select 'C03','立小丽'union all
select 'C02','朱列夫'union all
select 'C01','天任浩'union all
select 'C04','天里浩'union all
select 'C06','叶平'
 
select * from Course
select * from SC
select * from student
 
--Student(S#,Sname,Sage,Ssex) 学生表
--Course(C#,Cname,T#) 课程表
--SC(S#,C#,score) 成绩表
--Teacher(T#,Tname) 教师表
 
--问题:
--1、查询“”课程比“”课程成绩高的所有学生的学号:
select distinct S# from SC as sc where
(select score from sc as sc1 where c#='001' and sc1.s#=sc.s#)>
(select score from sc as sc2 where c#='002' and sc2.s#=sc.s#)
 
select S# from SC s where C#='001' and  score


相关文档:

解决SQL Server转ACCESS自动编号问题

1.打开SQL server enterprise mananger "企业管理器"
在你要导出的 SQL数据库上鼠标右键菜单:所有任务-》导出数据

2.回出现一个导出向导窗口。
选择被导出的数据源,为你刚才所选择的数据库,如果发现不对应自行修改。

3.进入导出到目标数据源的选择,这里我们要转成ACCESS的数据库。注意选择数据源类型为&ld ......

orale中sql语句对null值的处理

第一种方法:使用NVL函数处理NULL值。
其语法格式是NVL(exp1,exp2)。其中参数exp1和exp2可以使任意数据的类型,但两者数据类型必须匹配。示例:select ename,sal,comm,sal+nvl(comm,0) as salary from emp;
第二种方法:使用NVL2函数处理NULL值。
其语法格式是NVL2(exp1,exp2,exp3)。这是oracle9i新增加的函数。如果exp1 ......

Sql Server 2005 Express启用sa帐户

问题描述:
       Express版用sa帐户登录时失败
解决方案:
       第一步:用Windows身份登录Management Studio,右击服务器选择属性,将安全性选项 更改为:SQL Server 和 Windows
身份验证
         & ......

巧用SQL中的WITH(树型结构数据的查询)

如果表中存放的数据是树形结构,当知道某一个节点的值时,同时想取得它所有子节点的数据。
表结构:
        
         
 表中存放的是部门组织结构, BMN_CD部门,SSK_KAISO_LV是阶层,BMN_MKJ部门名称,JOI_KAISO_LV上 ......

SQL执行顺序

一、sql语句的执行步骤:
1)语法分析,分析语句的语法是否符合规范,衡量语句中各表达式的意义。
2) 语义分析,检查语句中涉及的所有数据库对象是否存在,且用户有相应的权限。
3)视图转换,将涉及视图的查询语句转换为相应的对基表查询语句。
4)表达式转换, 将复杂的 SQL 表达式转换为较简单的等效连接表达式 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号