测试一下自己的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
相关文档:
第一种方法:使用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执行导出来。
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver @server = N'TEST2', @srvproduct=N'ORCL', @provider=N ......
oracle中sql语句中select * from t_Test t where t.Id in(1,2,3......)/*数量不能大于1000个*/
解决方法 分割成多次in 然后再或上 如 select * from t_Test t where t.Id in(1,2,3......800) or t.Id in(801,802,803......1300)
在使用中最好能不使用其他条件来代替in
......
最近在做一个数据统计,要求对一个表中的数据按照两个维度呈现,也就是传统的交叉表
比如,有一个问题表,有三个字段,(标题、问题类别、问题状态)
要求按照不同的类别,分别统计处各个状态的问题数量(如:产品问题中未处理的数量、服务问题中遗留问题数量等等)。
经过查找和尝试,终于生成了结果,现在分享给大家。 ......
create table bookitem
(
bookname varchar(80) not null,
book_price Decimal(5,2) not null,
quantity int not null
)
insert into bookitem values('Image Processing',34.95,8)
insert into bookitem values('Signal Processing',51.75,6)
insert into bookitem values('Singal And System',48.5,10)
......