2013年7月11日

摘要: 1 select LEN('哈哈hello') --返回字符的个数 2 select datalength('哈哈hello') --返回时字节个数 3 select LOWER('AaBb') 4 select upper('AaBb') 5 select '======'+RTRIM(ltrim(' aaa '))+'=======' 6 --从左边数,截取10个字符 7 select left('hello welcome to china.',10) 8 -- 阅读全文
posted @ 2013-07-11 22:36 大钢 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 1 --===========================类型转换=============================2 3 select CAST(100 as varchar(10)) + 'hello'4 select convert(varchar(10),100) + 'hello'5 select CONVERT(varchar(50),getdate(),101)6 select * from test order by CAST(myid as int) desc 阅读全文
posted @ 2013-07-11 21:57 大钢 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 5>…Select 5-1>选择列,5-2>distinct,5-3>top1>…From 表2>…Where 条件3>…Group by 列4>…Having 筛选条件6>…Order by 列 1 select 2 --distinct / top 之类的关键字(这些都是一些实现选项 3 fgender as 性别, --5>选择列 4 COUNT(*) as 人数 5 from Mystudent --1>先从Mystudent表中拿到数据(全部数据的一个结果集) 6 where fage > 30 --2>从 阅读全文
posted @ 2013-07-11 20:19 大钢 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 一、order by 1 --先按英语成绩排序,再按数学成绩排序 2 --默认不谢排序方式时是asc(升序) 3 select * from Mystudentorder 4 order by FEnglish desc,FMath desc 5 6 --查询学生的姓名,英语成绩,数学成绩,平均分 7 select 8 fname 姓名 9 fmath 数学成绩10 fenglish 英语成绩11 平均分=(fmath+fenglish) / 2.012 from Mystudent13 order by (fmath+fenglish) / 2.0 de... 阅读全文
posted @ 2013-07-11 20:15 大钢 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 1 --1.请查询出学生表中所有数学成绩为null的的人的信息 2 --null 在数据库中表示unknown(不知道),判断一个值是否为null,也就不能用=或者 3 --null与null比较结果还是null(null)就表示不知道,‘不知道’在where中就认为是false,所以不返回任何数据 4 --查询所有fmath为null的值 5 select * from MyStudent 6 where fmath is null 7 --查询所有fmath 为非空的值 8 select * from MyStudnet where fmath is not null 9 --null值. 阅读全文
posted @ 2013-07-11 18:06 大钢 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 1 2 --求最高分 3 select MAX(fMath) as 数学成绩最高分 from MyStudent 4 --求最低分 5 select MIN(fMath) as 数学成绩最低分 from MyStudnet 6 --求总分 7 select SUM(fmath) as 总分 from MyStudent 8 --求平均分,对空值不处理 9 select AVG(fmath) as 平均分 from MyStudnet10 --求班级总人数,对空值不考虑11 select COUNT(*) as 班级总人数 from MyStudent12 --错误,因为聚合函数是把多条... 阅读全文
posted @ 2013-07-11 16:31 大钢 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 一、代码增加约束 1 --手动删除一列(删除EmpAddress列) 2 alter table Employees drop column EmpAddress 3 4 --手动增加一列(增加一列EmpAddr varchar(1000)) 5 alter table Employees add EmpAddr varchar(1000) 6 7 --手动修改一下EmpEmail的数据类型(varchar(200)) 8 alter table Employees alter column EmpAddr varchar(200) 9 10 --为... 阅读全文
posted @ 2013-07-11 14:20 大钢 阅读(248) 评论(0) 推荐(0) 编辑

导航