Sql Server 包含用法
SELECT b.*, (CASE WHEN EXISTS
(SELECT 1 FROM QZJ_UseRegDriverInUsing as a
WHERE b.ItemId = a.UseRegDriverID AND
isUseRegCancel = 0 AND
isApply = 1) THEN '锁定' ELSE '未锁定' END) AS isUsing
FROM QZJ_UseRegDriver b
问题:
检查本次考试,本班如果有人笔试成绩达到80分以上,则每人提2分。否则,每人允许提5分。
分析:
是否有人笔试成绩达到80分以上,可以采用EXISTS检测。SQL语句如示例8所示。
示例8
/*--采用EXISTS子查询,进行酌情加分--*/
IF EXISTS (SELECT * FROM stuMarks WHERE writtenExam>80)
BEGIN
print '本班有人笔试成绩高于分,每人加分,加分后的成绩为:'
UPDATE stuMarks SET writtenExam=writtenExam+2
SELECT * FROM stumarks
END
ELSE
BEGIN
print '本班无人笔试成绩高于分,每人可以加分,加分后的成绩:'
UPDATE stuMarks SET writtenExam=writtenExam+5
SELECT * FROM stumarks
END
GO
生活不是用眼泪博得同情 而是用汗水赢得掌声