日期:2014-05-17 浏览次数:20480 次
select name ,gender from student where [deleted]=0
--IF object_id('Student')>0
-- DROP TABLE dbo.Student
--GO
----学生信息表
--CREATE TABLE Student(
-- Id INT PRIMARY KEY IDENTITY(1,1),
-- [Name] VARCHAR(10) NOT NULL,--学生姓名
-- Result INT NOT NULL,--成绩
-- UnitedId INT NOT NULL--年级信息表外键
--)
--IF object_id('United')>0
-- DROP TABLE United
--GO
----年级信息表
--CREATE TABLE United(
-- Id INT PRIMARY KEY IDENTITY(1,1),
-- [NjName] VARCHAR(10) NOT NULL,--年级
-- [BjName] varchar(10)--班级
--)
--INSERT dbo.United(NjName,BjName)
-- SELECT '一年级','1班' UNION
-- SELECT '一年级','2班' UNION
-- SELECT '二年级','1班' UNION ALL
-- SELECT '二年级','2班'
--INSERT dbo.Student(Name,Result,UnitedId)
-- SELECT '张三',80,1 UNION
-- SELECT '李四',90,2 UNION
-- SELECT '王五',88,3 UNION
-- SELECT '小刘',60,4 UNION
-- SELECT '小张',78,3 UNION
-- SELECT '小李',82,1 UNION ALL
-- SELECT '小黑',30,3
create PROC abc
AS
SELECT s.*,u.njname+bjname '班级'
FROM student s INNER JOIN united u ON s.UnitedId=u.id
WHERE result>60 AND NjName +BjName IN ('一年级1班','二年级1班')
go
EXEC abc
/*
Id Name Result UnitedId &