查询添加帮助 [英] Query add help

查看:70
本文介绍了查询添加帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加两个查询结果并在第三列显示



zh
DECLARE @ Cnt1 int,@ Cnt2 int,@ result int, 
$
@res int



选择计数(1)来自REG的TOTAL_COUNT 

其中MCR_TMEOFREG< ; ='2019-02-06 15:00:50.853'



$

选择计数(1 )REG_HIST中的TOTAL_COUNT,其中 

TM_DREG介于'2019-02-06 15:00:50.853'和  Getdate()

和TM_REG< ='2019-02 -06 15:00:50.853'
$


选择@ result = @ Cnt1 + @ Cnt2

返回@result;

$


b
预期结果:



总计数



10¥
7

17 - 总计数

I want to add two query result and show in third column


DECLARE @Cnt1 int,@Cnt2 int,@result int, 
@res int

select count(1) TOTAL_COUNT from REG 
where MCR_TMEOFREG<='2019-02-06 15:00:50.853'



select count(1) TOTAL_COUNT FROM REG_HIST where 
TM_DREG between '2019-02-06 15:00:50.853' and  Getdate()
and TM_REG<='2019-02-06 15:00:50.853'

select @result=@Cnt1+@Cnt2
return @result;



expected result:

Total Count

10
7
17 -- Total Count

推荐答案

SELECT(从REG中选择count(1)TOTAL_COUNT个< b $ b,其中MCR_TMEOFREG< ='2019-02-06 15:00:50.853')+

(选择count(1)来自REG_HIST的TOTAL_COUNT个 

TM_DREG之间'2019-02-06 15:00:50.853'和  Getdate()

和TM_REG< ='2019-02-06 15:00:50.853')
SELECT (select count(1) TOTAL_COUNT from REG 
where MCR_TMEOFREG<='2019-02-06 15:00:50.853')+
(select count(1) TOTAL_COUNT FROM REG_HIST where 
TM_DREG between '2019-02-06 15:00:50.853' and  Getdate()
and TM_REG<='2019-02-06 15:00:50.853')


这篇关于查询添加帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆