本文介绍了如何在sql server中查找表中的总列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好 这里我对此查询有疑问我想要总列数, 我的查询: 选择 distinct rd.UserID,sm.EmpNameC,( select count(UserId)来自 RawData where TimeEntry ' 06 / Nov / 2014 09:00:00 AM' 和 ' 06 / Nov / 2014 10:00:00 AM') as ' BreakFast' 来自 RawData rd inner join StaffMaster as sm on rd.UserID = sm.UserIdN 输出喜欢: BreakFast 0 0 0 0 像这样我想要这个专栏的总和,做什么.... 解决方案 选择非重复计数(UserId) 来自 RawData 其中 ' 06 / Nov /之间的TimeEntry 2014 09:00:00 AM' 和' 06 / Nov / 2014 10:00 :00 AM') as ' BreakFast ' 来自 RawData as rd inner 加入 StaffMas ter as sm on rd.UserID = sm.UserIdN 试试这个: 选择 * from( select distinct rd.UserID,sm.EmpNameC from RawData as rd inner join StaffMaster as sm on rd.UserID = sm.UserIdN)t1 inner join (选择 count(UserId),userId 来自 RawData 其中 TimeEntry ' 06 / Nov / 2014 09:00:00 AM' 和 ' 06 / Nov / 2014 10:00:00 AM' group by userId)t2 on t1.userId = t2.userId 语法为: 选择 * from( select userId,name from table1) t1 内部 join ( select count(userid ),名称来自 table2)t2 on t1.userId = t2.userId hi All Here i have problem with this query i want total number of columns,My Query:select distinct rd.UserID,sm.EmpNameC,(select count(UserId) from RawData where TimeEntry between '06/Nov/2014 09:00:00 AM' and '06/Nov/2014 10:00:00 AM') as 'BreakFast' from RawData as rd inner join StaffMaster as sm on rd.UserID=sm.UserIdNOutput Like:BreakFast0000like this i want total sum of this column, what to do.... 解决方案 select distinct count(UserId)from RawDatawhere TimeEntry between '06/Nov/2014 09:00:00 AM'and '06/Nov/2014 10:00:00 AM') as 'BreakFast'from RawData as rdinner join StaffMaster as smon rd.UserID=sm.UserIdNtry this:select *from ( select distinct rd.UserID,sm.EmpNameC from RawData as rd inner join StaffMaster as sm on rd.UserID=sm.UserIdN) t1 inner join (select count(UserId),userId from RawData where TimeEntry between '06/Nov/2014 09:00:00 AM' and '06/Nov/2014 10:00:00 AM' group by userId) t2 on t1.userId=t2.userIdThe Syntax is :select *from (select userId,name from table1)t1 inner join (select count(userid),name from table2)t2 on t1.userId=t2.userId 这篇关于如何在sql server中查找表中的总列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 23:59