create DATABASE students
create TABLE t_soures(
c_number char(10) not null PRIMARY key,
c_name char(30) not null,
hours int ,
credit real
)
create TABLE t_score(
s_number char(10) foreign key references
)
USE [students];
GO
DROP TABLE [dbo].[t_soures];
GO
select s_number, t_socre.c_number, socer FROM t_socre, t_sourse where (dbo.t_socre.c_number = dbo.t_sourse.c_number)
select * FROM t_socre where socer <90
select * from t_student where polity='团员' AND sex='男'
BETWEEN 是在一个范围 (range) 内抓出数据库中的值。BETWEEN 这个子句的语法如下:
这将选出栏位值包含在值一及值二之间的每一笔资料。
在 SQL 中,在这个用法下,事先已经知道至少一个需要的值,而将这些知道的值都放入 IN这个子句。 IN 指令的 语法为下:
在括弧内可以有一或多个值,而不同值之间由逗点分开。值可以是数目或是文字。若在括弧内只有一个值,那这个子句就等于
select * from t_student where polity in('团员','非')
select * from t_student where birthday BETWEEN '1996/12/1' AND '1997/2/2'
USE [students];
GO
DROP TABLE [dbo].[t_soures];
GO
select * FROM t_student, t_socre where dbo.t_student.s_number = dbo.t_socre.s_number
select * from t_student inner join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number
/* 左连
显示左表T1中的所有行,并把右表T2中符合条件加到左表T1中;右表T2中不符合条件,就不用加入结果表中,并且NULL表示。*/
select * from t_student left outer join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number
/* 右表无004信息 所以用null代替 */
/* 右连
显示右表T2中的所有行,并把左表T1中符合条件加到右表T2中;左表T1中不符合条件,就不用加入结果表中,并且NULL表示。*/
select * from t_student right outer join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number
/* 全连
显示左表T1、右表T2两边中的所有行,即把左联结果表+右联结果表组合在一起,然后过滤掉重复的 */
select * from t_student full outer join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number
/*
update 员工表
set 部门编号=
01 --如果
01是字符型,则加上单引号
where 员工编号=
update t_socre
set s_number=
*/
select *
from t_student
where s_number = any (
select s_number
FROM t_socre
Group by s_number
having COUNT(c_number)>=
2
)
create table t_student
(
s_number char(10) primary key,
s_name char(30) ,
sex char(2) default '男',
birthday datetime,
polity char(4)
)
转载请注明原文地址: https://ju.6miu.com/read-971249.html