关于SQL Server查询语句的使用
2022-11-12 09:41:59
内容摘要
这篇文章主要为大家详细介绍了关于SQL Server查询语句的使用,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
一.查询第二个字母是t或者a
文章正文
这篇文章主要为大家详细介绍了关于SQL Server查询语句的使用,具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
一.查询第二个字母是t或者a的雇员的全部信息
代码如下:
1 2 3 4 | <code>select * from employees where firstname like '_[t,a]%' </code> |
二.更改字段名
代码如下:
1 2 3 4 | <code>select '名字' = firstname , '姓氏' = lastname from employees where firstname like '_[t,a]%' </code> |
代码如下:
1 2 3 4 | <code>select firstname as '名字' , lastname as '姓氏' from employees where firstname like '_[t,a]%' </code> |
代码如下:
1 2 3 4 5 6 7 8 | <code> /*检索出符合条件的前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]%' </code> |
代码如下:
1 2 3 4 5 6 7 8 | <code>select * from employees where title = 'Sales Manager' union select * from employees where address is not null </code> |
服务器: 消息 8163,级别 16,状态 4,行 1不能以 DISTINCT 方式选择 text、ntext 或 image 数据类型。
代码如下:
1 2 3 4 5 6 7 8 | <code>select * from employees where title = 'Sales Manager' union all select * from employees where address is not null </code> |
五.compute关键字
compute子句需要以下信息:可选的By关键字可按对一列计算指定的行聚合行聚合函数:sum,avg,min,max,count要对其执行行聚合函数的列当compute带有可选的By子句时,符合select条件的每个组都有两个结果集:每个组的第一个结果集是明细行集,其中包含该组的选择列表信息每个组的第二个结果集有一行,其中包含该组COMPUTE子句中所指定的聚合函数的小记
代码如下:
1 2 3 4 5 | <code>select sex,sclass,score from student order by sex compute sum(score) by sex </code> |
【图片暂缺】
注意:order by是必须的,并且 compute by后的参数应该在order by后的参数中出现过
代码如下:
1 2 3 4 | <code>select sex,sclass,score from student compute sum(score) </code> |
【图片暂缺】
注:关于关于SQL Server查询语句的使用的内容就先介绍到这里,更多相关文章的可以留意
代码注释