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

问题描述

大家好,请帮我解决这个问题



选择TOP(1)SUM(ld.Id)作为SUMOFTBL1,SUM(um.Id)作为SUMOFTBL2来自LoginData ld,UploadMaster um



这给了我不正确的结果



但如果我这样做就像

选择TOP(1)SUM(ld.Id)作为来自LoginData的SUMOFTBL1 ld

选择TOP(1)SUM(um.Id)为SUMOFTBL2 UploadMaster嗯



它给我正确的结果



我的目标是减少sql代码

并把这一起...

Hi guys please help me with this query

select TOP(1) SUM(ld.Id) as SUMOFTBL1,SUM(um.Id) as SUMOFTBL2 from LoginData ld,UploadMaster um

this gives me incorrect result

but if i do it seprately like
select TOP(1) SUM(ld.Id) as SUMOFTBL1 from LoginData ld
select TOP(1) SUM(um.Id) as SUMOFTBL2 UploadMaster um

it gives me correct result

my objective is to reduce sql code
and put this together...

推荐答案

Select (select SUM(ld.Id) from LoginData ld) as SUMofTBL1, (select SUM(um.Id) from UploadMaster um) as SUMofTBL2





这是一个COUNT:



Here is a COUNT:

Select (select COUNT(*) from LoginData) as COUNTofTBL1, (select COUNT(*) from UploadMaster) as COUNTofTBL2


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

08-18 22:12