今天给大家介绍SQLServer中交叉联接的用法,希望对大家能有所帮助!
2024年08月31日
在以前经常使用mssql server做数据库,现在人工智能席卷全球。今年改用sqlite3做数据库,虽然都是关系型数据库,都支持sql标准语法,但是在实际使用中依然有细微差别。常言道细节决定成败。在自己使用过程中就发现在mssql server经常使用的东西在sqllite3无法运行。有几个遇到情况如下:
2024年08月31日
--分页显示存储过程
if(exists(select * from sys.objects where name='pr_ShowPage'))
drop proc pr_ShowPage
go
create proc pr_ShowPage
(
2024年08月31日
--插入测试数据
select '基层员工' as '范围',21826 as '在职人数',497 as '离职人数',201812 as '时间' into #T
union all
select '主管级及以上员工' as '范围',3904 as '在职人数',40 as '离职人数',201812 as '时间'
union all
select '基层员工' as '范围',21835 as '在职人数',488 as '离职人数',201901 as '时间'
union all
select '主管级及以上员工' as '范围',3883 as '在职人数',19 as '离职人数',201901 as '时间'
union all
select '基层员工' as '范围',21819 as '在职人数',472 as '离职人数',201902 as '时间'
union all
select '主管级及以上员工' as '范围',3900 as '在职人数',36 as '离职人数',201902 as '时间'
union all
select '基层员工' as '范围',22095 as '在职人数',748 as '离职人数',201903 as '时间'
union all
select '主管级及以上员工' as '范围',3914 as '在职人数',50 as '离职人数',201903 as '时间'
union all
select '基层员工' as '范围',22006 as '在职人数',659 as '离职人数',201904 as '时间'
union all
select '主管级及以上员工' as '范围',3927 as '在职人数',63 as '离职人数',201904 as '时间'
union all
select '基层员工' as '范围',22080 as '在职人数',733 as '离职人数',201905 as '时间'
union all
select '主管级及以上员工' as '范围',3935 as '在职人数',71 as '离职人数',201905 as '时间'
union all
select '基层员工' as '范围',22016 as '在职人数',669 as '离职人数',201906 as '时间'
union all
select '主管级及以上员工' as '范围',3935 as '在职人数',71 as '离职人数',201906 as '时间'
union all
select '基层员工' as '范围',22039 as '在职人数',692 as '离职人数',201907 as '时间'
union all
select '主管级及以上员工' as '范围',3911 as '在职人数',47 as '离职人数',201907 as '时间'
union all
select '基层员工' as '范围',22061 as '在职人数',714 as '离职人数',201908 as '时间'
union all
select '主管级及以上员工' as '范围',3934 as '在职人数',70 as '离职人数',201908 as '时间'
union all
select '基层员工' as '范围',21904 as '在职人数',557 as '离职人数',201909 as '时间'
union all
select '主管级及以上员工' as '范围',3913 as '在职人数',49 as '离职人数',201909 as '时间'
union all
select '基层员工' as '范围',21905 as '在职人数',558 as '离职人数',201910 as '时间'
union all
select '主管级及以上员工' as '范围',3902 as '在职人数',38 as '离职人数',201910 as '时间'
union all
select '基层员工' as '范围',21915 as '在职人数',568 as '离职人数',201911 as '时间'
union all
select '主管级及以上员工' as '范围',3907 as '在职人数',43 as '离职人数',201911 as '时间'
union all
select '基层员工' as '范围',21929 as '在职人数',482 as '离职人数',201912 as '时间'
union all
select '主管级及以上员工' as '范围',3905 as '在职人数',41 as '离职人数',201912 as '时间'
select * from #T
?
declare @sql varchar(max) =''
select @sql = @sql+
',max(case when a.时间='+cast(t.时间 as varchar(20))+' then a.在职人数 else NULL end) 在职人数 '+
',max(case when a.时间='+cast(t.时间 as varchar(20))+' then a.离职人数 else NULL end) 离职人数 '+
',max(case when a.时间='+cast(t.时间 as varchar(20))+' then a.时间 else NULL end) 时间 '
from #T t group by t.时间
set @sql = 'select a.范围'+ @sql +'from #T a group by a.范围'
--set @sql = 'select * from #T'
print(@sql)
exec(@sql)
2024年08月31日
关于SQL SERVER 数据库日常维护,管理,巡检过程中可能经常需要用到一些SQL语句(亦或方法)来查看数据库服务器环境(操作系统版本, 磁盘空间,CPU,RAM信息),数据库信息(数据库版本,实例名称...),数据库对象等。内容比较多,所以分两次做介绍。
2024年08月31日
一.需求背景
SQL Server开源的归档工具不多,DBA一般都是通过计划任务来触发执行,执行的脚本多是SP或者是SSIS包。SSIS包的性能稍好一些,但是维护更新成本高些。所以更常见的是通过SP脚本来实现归档操作。
当数据库规模较小时,可以方便的直接在数据库上进行脚本的编写部署。但是随着数据库越来越多,管理维护成本就会越来越大,越来越不方便。现在我们实行的方式是通过中央管理器来管理众多的数据库备份(这是在拥有专门的备份程序前的一个过渡方案)。我们将归档基础配置信息、归档运行历史记录、异常报错等数据统一维护在中央数据库上。如此,可以方便统一的查看、管理和维护。
2024年08月31日
让我们通过一个示例来了解 SQL Server 中异常处理的必要性。因此,创建一个 SQL Server 存储过程,通过执行以下查询来除以两个数字。
2024年08月31日
毕业开始从事winfrm到今年转到 web ,在码农届已经足足混了快接近3年了,但是对安全方面的知识依旧薄弱,事实上是没机会接触相关开发……必须的各种借口。这几天把sql注入的相关知识整理了下,希望大家多多提意见。