50个常用sql语句
50个常用sql语句
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
from SC where C#='002') b
where a.score>b.score and a.s#=b.s#;
2、查询平均成绩大于60分的同学的学号和平均成绩;
select S#,avg(score)
from sc
group by S# having avg(score) >60;
3、查询所有同学的学号、姓名、选课数、总成绩;
select Student.S#,Student.Sname,count(SC.C#),sum(score)
from Student left Outer join SC on Student.S#=SC.S#
group by Student.S#,Sname
4、查询姓“李”的老师的个数;
select count(distinct(Tname))
from Teacher
where Tname like '李%';
5、查询没学过“叶平”老师课的同学的学号、姓名;
select Student.S#,Student.Sname
from Student
where S# not in (select distinct( SC.S#) from SC,Course,Teacher where SC.C#=Course.C# and Teacher.T#=Course.T# and Teacher.Tname='叶平');
6、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
select Student.S#,Student.Sname from Student,SC where Student.S#=SC.S# and SC.C#='001'and exists( Select * from SC as SC_2 where SC_2.S#=SC.S# and SC_2.C#='002');
7、查询学过“叶平”老师所教的所有课的同学的学号、姓名;
select S#,Sname
from Student
where S# in (select S# from SC ,Course ,Teacher where 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='叶平'));
8、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;
Select S#,Sname from (select Student.S#,Stud
相关文档:
最近在做一个注册程序,得用得密码的MD5加密,直接在存储过程中进行注册。
查找得到,可用以下方法进行加密:
print RIGHT(sys.fn_VarBinToHexStr(hashbytes('MD5','ANSEN')),32)
数据库是用SQL SERVER 2005,其他的数据库应该也差不到哪去~~ ......
@echo off
rem Input Parameters:
rem 1 -Server Name
rem 2 -Database Name
if "%1"=="" goto ERROR
if "%2"=="" goto ERROR
@rem Make variables local
@Setlocal
@rem set variables from input parameters
set Server=% 1
set DBName=% 2
@rem------------------------------------------------------------ ......
--> Title : 某外企SQL Server面試題
--> Author : wufeng4552
--> Date : 2010-1-15
Question 1:Can you use a batch SQL or store procedure to calculating the Number of Days in a Month
Answer 1:找出当月的天数
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast( ......
--8-1
USE Northwind
SELECT * from ::fn_dblog('', '')
GO
--8-2
USE Northwind
SELECT * from ::fn_dblog('', '') WHERE [Begin Time] >= '02/01/07'
GO
--9-1
SELECT *
from master.dbo.sysprocesses
--9-2
SELECT *
from sys.dm_exec_requests
--9-3
DECLARE @Handle varbinary(64);
SEL ......
Oracle SQL与ANSI SQL区别
相信大家都使用过SQL SERVER。今天给大家简单介绍一下Oracle SQL与ANSI SQL区别。其实,SQL SERVER与与ANSI SQL也有区别。
1、首先大家要明白什么是ANSI
ANSI:美国国家标准学会(American National Standards Institute)。当时,美国的许多企业和专业技术团体,已开始了标准化工作,但因彼 ......