union以及一些扩展
select name,age from Students where Age<3
union
select name ,age from Students where Age >4
--两个结果集要有相同数目的列还要有相同的数据类型(至少要可以隐式转换的)
select name 姓名,age 年龄 from Students where Age<3
union
select name ,age from Students where Age >4
--列名是第一个决定的
select name 姓名,age 年龄 from Students where Age<3
union
select name ,age from Students where Age >4
union
select name ,age from Students where Age >4
--union会自动去除重复项
select name 姓名,age 年龄 from Students where Age<3
union all
select name ,age from Students where Age >4
union all
select name ,age from Students where Age >4
--union all不会把重复的项去掉
select name,gender from Students
union all
select name ,cast(gender as nvarchar(10)) from Classes
--如果类型不同可以通过cast进行尝试转换
select '最高分:'+CAST( MAX(English)as nvarchar(10))from score --最高分
union all
select '最低分:'+CAST( MIN (English) as nvarchar(10)) from score -- 最低分
union all
select '平均分:'+cast(AVG(English)as nvarchar(10) )from score --平均分
--↑竖直的方式呈现
select '最高分:'+CAST( MAX(English)as nvarchar(10)),'最低分:'+CAST( MIN (English) as nvarchar(10)),'平均分:'+cast(AVG(English)as nvarchar(10) )from score
--水平方式显示↑
insert into Students( Name, Gender, Address, Phone, Age, Birthday, CardId, CId)select Name, Gender, Address, Phone, Age, Birthday, CardId, CId from Students
--把结果集查询出来再插入,表的列数,数据类型都要一样
union以及一些扩展的更多相关文章
- C++进阶3.字节对齐 联合
C++进阶3.字节对齐 联合 20131011 多益和金山笔试 知识漏洞 20131011 前言: 今天下午是多益网络的笔试,整体感觉还好,但是找到很多的知识漏洞.一直笔试到6:00,然后紧张的从会生 ...
- 为 CmakeLists.txt 添加 boost 组件
目录 为 CmakeLists.txt 添加 boost 组件 Boost 常用组件 1.时间与日期 timer, date_time, chrono 2.内存管理 system 3.实用工具库 4. ...
- 恢复SQL Server被误删除的数据(再扩展)
恢复SQL Server被误删除的数据(再扩展) 大家对本人之前的文章<恢复SQL Server被误删除的数据> 反应非常热烈,但是文章里的存储过程不能实现对备份出来的日志备份里所删数据的 ...
- .NET中那些所谓的新语法之二:匿名类、匿名方法与扩展方法
开篇:在上一篇中,我们了解了自动属性.隐式类型.自动初始化器等所谓的新语法,这一篇我们继续征程,看看匿名类.匿名方法以及常用的扩展方法.虽然,都是很常见的东西,但是未必我们都明白其中蕴含的奥妙.所以, ...
- ORA-01652:无法通过128(在表空间temp中)扩展temp段 解决方法
ORA-01652:无法通过128(在表空间temp中)扩展temp段 解决方法 (2016-10-21 16:49:53) 今天在做一个查询的时候,报了一个"ORA-01652无法通过 ...
- ora-01652无法通过128(在表空间temp中)扩展temp段
今天提交请求后,提示ORA-01652: 无法通过 128 (在表空间 TEMP 中) 扩展 temp 段.最后通过ALTER DATABASE TEMPFILE '/*/*/db/apps_st/d ...
- GROUP BY的扩展
GROUP BY的扩展主要包括ROLLUP,CUBE,GROUPING SETS三种形式. ROLLUP rollup相对于简单的分组合计增加了小计和合计,解释起来会比较抽象,下面我们来看看具体事例. ...
- 再谈扩展方法,从string.IsNullOrEmpty()说起
string.IsNullOrEmpty()这个方法算得上是.net中使用频率最高的方法之一.此方法是string的一个静态方法,类似的静态方法在string这个类中还有很多.那么这样的方法作为静态方 ...
- PHP扩展——C扩展实现滚动记录日志
前言 万事开头难,没错就是这样!! 在没有真正开发PHP扩展之前,一直觉得PHP扩展开发对我来说是一个很遥远的事情,虽然自己有些C\C++基础,但是看PHP源码的时候还是很吃力,现在看来主要还是没有下 ...
随机推荐
- JQuery 之事件中的 ----- hover 与 onmouseover 、onmouseout 联系
hover([over,]out) 一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法.这是一个自定义的方法,它为频繁使用的任务提供了一种“保持在其中”的状态. 当鼠标移动到一个匹配的元素 ...
- (原+转)ubuntu16中莫名死机及重新安装显卡驱动
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5992693.html 参考网址: http://blog.csdn.net/u012581999/ar ...
- 做一个正气的杭电人--hdu2500
做一个正气的杭电人 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- Proud Merchants(POJ 3466 01背包+排序)
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- iOS Plist NSUserDefaults 数据存储
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- sql中插入多条记录-微软批处理
这是使用批处理的一个例子: System.IO.StreamWriter messagelog = null; string messageString = ""; SqlConn ...
- android学习精要
第1章 初识android1.1 android平台概述1.2 android平台体系1.2.1 linux kernel内核层1.2.2 系统运行库libraries和android runtime ...
- jQuery 获取 URL信息
jQuery获取URL信息有很多方法,但是使用这个插件就非常爽了. 托管地址在:http://github.com/allmarkedup/jQuery-URL-Parser // http: //l ...
- http cookie
一.cookie的大小 cookie只能存储最大4kb的数据.cookie的名/值中的值不允许包含分号.逗号和空白符.因此可以采用encodeURIComponent()编码,读取的时候先采用deco ...
- undefined reference to `png_set_longjmp_fn'
这个是在Linux上编译项目的时候,一个动态库层用到的一个函数实现未找到,即使我链接了libpng2也没有找到,原因是这个库老了一些,没有这个函数定义,需要链接更高版本的png库,CentOS上有了在 ...