国产房车大全,中央政法委信息中心,367查查网
一.查询第二个字母是t或者a的雇员的全部信息
select *
from employees
where firstname like '_[t,a]%'
注意:在sql中%表示字符串,所以不可像matlab一样用其注释,两个双斜线好像也不行,/**/可以,有网友说sql单行注释为--
二.更改字段名
select '名字' = firstname ,'姓氏' = lastname
from employees
where firstname like '_[t,a]%'
或者
select firstname as '名字' , lastname as '姓氏'
from employees
where firstname like '_[t,a]%'
三.top关键字
/*检索出符合条件的前70%条记录*/
select top 70 percent firstname as '名字' , lastname as '姓氏'
from employees
where firstname like '_[t,a]%'1 /*检索出符合条件的前2条记录*/
select top 2 firstname as '名字' , lastname as '姓氏'
from employees
where firstname like '_[t,a]%'
四.union关键字
注意:标准sql只提供了并操作,未提供交(intersection)和差(minus)操作。
select *
from employees
where title = 'sales manager'
union
select *
from employees
where address is not null
显示:
服务器: 消息 8163,级别 16,状态 4,行 1
不能以 distinct 方式选择 text、ntext 或 image 数据类型。
select *
from employees
where title = 'sales manager'
union all
select *
from employees
where address is not null
查询分析其中的分析查询(对号)是看下是否有语法错误(ctrl + f5),执行查询(右三角)(f5)是显示结果的若有语法错误则不执行。
五.compute关键字
compute子句需要以下信息:
可选的by关键字可按对一列计算指定的行聚合
行聚合函数:sum,avg,min,max,count
要对其执行行聚合函数的列
当compute带有可选的by子句时,符合select条件的每个组都有两个结果集:
每个组的第一个结果集是明细行集,其中包含该组的选择列表信息
每个组的第二个结果集有一行,其中包含该组compute子句中所指定的聚合函数的小记
select sex,sclass,score
from student
order by sex
compute sum(score) by sex
注意:order by是必须的,并且 compute by后的参数应该在order by后的参数中出现过
select sex,sclass,score
from student
compute sum(score)
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
网友评论