- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
SQLServer表与列别名,计算列等等的说明及例子
语句所用表说明
第一章:
1.select 语句中使用列别名
在select 语句中使用列别名的例子中利用的表是学生表(studenttable),学生表中有字段
studentid(学生学号) 从1开始自动增长1,主键,不可以为空。
studentname(学生姓名)不可以为空。
studentsex(学生性别)唯一约束,只能为男或者女,不可以为空。
studentage(学生年龄)唯一约束,年龄范围在10-35之间,不可以为空。
在select语句中使用列别名有四种使用方法:
(1)用as关键字
例:select studentid as 学号 from studenttale where studentname = ‘值’
(2)用双引号
例:select studentid “学号” from studenttable where studentname = ‘值’
(3)用单引号
例:select studentid ‘学号’ from studenttable where studentname =’值’
(4)不带引号
例:select studentid 学号 from studenttable where studentname =’值’
2.select 语句中使用计算列
在select语句中使用计算列利用的表是商品表(commoditytable),商品表中有字段
Commodityid(商品编号)从1开始自动增长1,主键,不可以为空。
Commodityname(商品名称)不可为空。
Commoditystock(商品进货数量)不可为空。
Commoditysell(商品售出数量)不可为空。
Commodityunit(商品进价)不可为空。
Commoditybid(商品单价)不可为空。
(1)计算库存数量
例:select (commoditystock-commoditysell)as 库存数量 from commoditytable
(2)计算已卖商品利润
例:select (commoditybid-commodityunit)*commoditysell ‘已卖商品获得利润’ from commdoitytable
(3)计算库存利润
例:select (commoditystock-commoditysell)* (commoditybid-commodityunit) as 库存利润
From commdoitytable
3.使用表别名查询数据
表别名和列别名几乎相同,在此例中我们利用学生表(studenttable)进行说明
(1)利用as关键字
例:select student.* from studenttable as student
(2)利用双引号
例:select student.*from studenttable “student”
(3)不带引号
例:select student.* from studenttable student
三种方法中均可以给where条件
例:select student.* from studenttable student where student.Studentid = ‘值’
注意:列别名可以用单引号(‘’),而表别名不可以用单引号。
4.在where子句使用计算列
Where子句中使用计算列和在select语句中使用计算列几乎相同,所以在此例中我们利用商品表(commoditytable)进行说明。
(1)计算库存数量为5的商品信息
例:select commodity.* from commoditytable as commodity where (moditysell) = 5
(2)计算已卖商品利润大于35的商品信息
例:select commodityid as 编号,commodityname 商品名称,commoditystock 进货总量,commoditysell 已售数量,
commodityunit 进价,commoditybid 单价from commoditytable where (commoditybid-commodityunit) 35
(3)计算库存利润小于200的商品信息
例:select commodity.* from commoditytable as commodity
Where (moditystock –moditysell)*(moditybid-commodity.unit) 200
注意:select语句中使用计算列是可以直接给出计算结果的,而在where子句中只能做对比的,
5.利用begin…end批处理执行多条
文档评论(0)