zoukankan
html css js c++ java
获取某命名规则下一系列表的总条数
SQLServer(T-SQL):
--
获取某命名规则下的
--
场景:有1000个后缀逐渐递增的表(如果是上万了也可做相应的改动实现),获取这些表总的数据条数
--
表的形式:tb_user000,tb_user001,tb_user010,tb_user011,tb_user999
--命名规则
:000,001...009,010,011..999
declare
@i
int
--
表开始后缀
declare
@str
nvarchar
(
1000
)
--
执行语句
declare
@tab
varchar
(
100
)
--
表前缀
declare
@tab_suffix
varchar
(
10
)
--
表后缀
declare
@max
int
--
表个数
set
@i
=
0
set
@tab
=
'
tb_user
'
set
@max
=
1000
if
exists
(
select
*
from
tempdb.dbo.sysobjects
where
id
=
OBJECT_ID
(
'
tempdb..#t1
'
)
and
xtype
=
'
U
'
)
drop
table
#t1
create
table
#t1(id
int
identity
(
1
,
1
),num
int
,tab
varchar
(
100
))
while
@i
<
@max
begin
if
@i
>=
0
and
@i
<
10
set
@tab_suffix
=
'
00
'
else
if
@i
>
9
and
@i
<
100
set
@tab_suffix
=
'
0
'
else
if
@i
>
99
and
@i
<
1000
set
@tab_suffix
=
''
set
@str
=
N
'
insert into #t1(num,tab) select Total,
'''
+
@tab
+
@tab_suffix
+
cast
(
@i
as
varchar
)
+
'''
from
(select Total = count(*) from
'
+
@tab
+
@tab_suffix
+
cast
(
@i
as
varchar
)
+
'
) a
'
print
@str
;
exec
sp_executesql
@str
;
set
@i
=
@i
+
1
;
end
select
num,tab,sum_num
from
(
select
sum
(num)
as
sum_num
from
#t1) b,#t1
显示结果如下:
作者:
青羽
查看全文
相关阅读:
nginx + keepalived 教程
mysql 之 获取指定月份天数和指定月份上月天数
hive 之将sql执行结果输出到文件中
sql 之 处理一行全为0的记录
Shell 基础知识
kettle 调度时出现时区问题,导致数据调出加了8小时
sql 之按指定分割符取分割符前/后字符串
Spring Security(二)
Spring Security(一)
集成Swagger文档
原文地址:https://www.cnblogs.com/tenghoo/p/1238808.html
最新文章
神经网络——安装Anaconda、Tensorflow
害虫图片爬取
爬虫————获取图片(scrapy使用自带类 ImagesPipeline)
爬虫 ——(50页)books
爬虫———通过pipeline以及items 将数据以json类型存储
爬取---Books to Scrape(第一页所有书名和价格)
爬虫 ----zhihuuser
搜索引擎技巧
python基础 格式化输出
windows使用技巧
热门文章
python应用 曲线拟合03
Python基础 读取二进制文件
python基础 类
c++基础 写二进制文件
shell 设置进程数运行
shell 文件判断
shell 逻辑判断
shell 之 dug调试
mysql.help_topic 将多个逗号隔开的字段转换为行(多条记录)
mysql 之 上周周六到本周周五时间
Copyright © 2011-2022 走看看