第二章 SQL 编程 , 类型转换 , if else , 上机练习
2017-01-09 14:56
549 查看
--字符串类型 declare @name nvarchar(32) -- 声明 set @name ='库里' -- 输出语句 print @name -- 数字类型 declare @balance decimal(18,2) set @balance=16.23 print @balance --日期类型 存储‘火火’出生日期 declare @birthday datetime set @birthday ='1998-02-18' print @birthday -- 数据类型转换 cast as declare @num int set @num = 500000 print '这个数是:'+ cast(@num as nvarchar(32)) -- 数据类型转换 convert declare @num1 int set @num1 = 3000 print '这个数是:::'+ convert(nvarchar(32),@num1) -- if else declare @age int set @age = 15 if(@age>=18) begin print'可以观看' end else begin print'不可以观看!再长几年吧' end --练习 --统计并显示2013-08-09的oop考试的平均分 --如果平均分在70分以上,显示“考试成绩优秀”,并显示前三名学生的考试信息 --如果在以下,显示“考试成绩较差”,并显示后三名学生的考试成绩 select * from result order by examdate --1.求出oop课程对应的课程编号 declare @subid int select @subid=SubjectId from Subject where subjectname='oop' --2.查询平均分 declare @avg int select @avg=avg(Studentresult) from result where examdate>='2013-08-09' and examdate<'2013-08-10' and subjectid=@subid if(@avg>=70) begin print '成绩优秀' --打印前三名的成绩 select top 3 * from result where examdate>='2013-08-09' and examdate<'2013-08-10' and subjectid=@subid order by studentresult desc end else begin print '成绩较差' --打印前三名的成绩 select top 3 * from result where examdate>='2013-08-09' and examdate<'2013-08-10' and subjectid=@subid order by studentresult end -- 上机一 declare @tu nvarchar(32) set @tu ='☆' print @tu print @tu+@tu print @tu+@tu+@tu print @tu+@tu+@tu+@tu print @tu+@tu+@tu+@tu+@tu -- 上机二 select studentno as '学号',StudentName as '姓名',FLOOR(DATEDIFF(dy,BornDate,getdate())/365) as '年龄' from dbo.Student where studentno='S1101001' declare @yy int select @yy=DATEPART(YY,BornDate) from student where studentno='S1101001' select * from student where DATEPART(YY,BornDate)=@yy+1 or DATEPART(YY,BornDate)=@yy-1 go -- 上机三 -- 1 查询课程id declare @id2 int select @id2=subjectid from Subject WHERE subjectname='java' -- 2 查询该学生的成绩 学号为 23219 declare @cheng int select @cheng=Studentresult from result where subjectid=@id2 and studentno=23219 --print @chengji if(@cheng>=85) begin Print '优秀!' end else if(@cheng>=70) begin Print '良好!' end else if(@cheng>=60) begin Print '中等!' end else begin Print '差!' end
相关文章推荐
- 练习2-10 重新编写将大写字母转换为小写字母的函数lower,并用条件表达式替代其中的if-else结构。
- 使用变量 数据类型转换 逻辑控制语句(begin ...end; case...end; if...else; while)
- 练习2-10 重新编写将大写字母转换为小写字母的函数lower,并用条件表达式替代其中的if-else结构。
- 练习2-10 重新编写将大写字母转换为小写字母的函数lower,并用条件表达式替代其中的if-else结构。
- java例程练习(数据类型转换)
- 算法竞赛入门经典 第二章 上机练习(C++代码)
- 《Visual C# 最佳实践》第二章 控制语句 (二):类型转换
- 练习:类型转换
- 【新人强化培训】c 语言强化练习1 :类型转换 和 最大值[zt]
- 算法竞赛入门经典 第二章 上机练习(C++代码)
- 算法竞赛-入门经典 第二章上机练习
- Traits技术:类型的if-else-then(STL核心技术之一)
- 第二章 JAVA语言基本语法————数据类型之间的转换
- Java中的byte类型及用if-else对三个数排序
- C语言基础教程读书笔记2(第二章常量、变量、类型转换)
- 用if-else语句编写利息计算器(第九周上机任务)
- C语言 初级练习(if-else语句篇)
- [转载] 第二章 struts2类型转换
- 利用转换表判断字符的类型(练习)
- day02标识符,二进制转换,位运算符,类型转换,if,switch