加入收藏 | 设为首页 | 会员中心 | 我要投稿 鹰潭站长网 (https://www.0701zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – MS ACCESS:如何使用访问查询计算不同的值?

发布时间:2021-02-22 21:43:03 所属栏目:MsSql教程 来源:网络整理
导读:这是下面给出的当前复杂查询. SELECT DISTINCT Evaluation.ETCode,Training.TTitle,Training.Tcomponent,Training.TImpliment_Partner,Training.TVenue,Training.TStartDate,Training.TEndDate,Evaluation.EDate,Answer.QCode,Answer.Answer,Count(Answer.Ans

这是下面给出的当前复杂查询.

SELECT DISTINCT Evaluation.ETCode,Training.TTitle,Training.Tcomponent,Training.TImpliment_Partner,Training.TVenue,Training.TStartDate,Training.TEndDate,Evaluation.EDate,Answer.QCode,Answer.Answer,Count(Answer.Answer) AS [Count],Questions.SL,Questions.Question
FROM ((Evaluation INNER JOIN Training ON Evaluation.ETCode=Training.TCode) INNER JOIN Answer ON Evaluation.ECode=Answer.ECode) INNER JOIN Questions ON Answer.QCode=Questions.QCode
GROUP BY Evaluation.ETCode,Training.Tvenue,Questions.Question,Questions.SL
ORDER BY Answer.QCode,Answer.Answer;

另一栏是Training.TCode.我需要计算明显的Training.TCode,有人可以帮帮我吗?
如果您需要更多信息,请告诉我

解决方法

尝试
select ...,count(distinct Training.Tcode) as ...,...

编辑 – 请现在看看这个……

采用以下SQL代码.第一个选择是SQL服务器如何执行此操作,第二个查询应该是访问兼容…

declare @t table (eCode int,tcode int)
insert into @t values(1,1)
insert into @t values(1,2)
insert into @t values(1,3)
insert into @t values(2,2)
insert into @t values(2,3)
insert into @t values(3,1)    

select 
    ecode,count(distinct tCode) countof
from
    @t
group by
    ecode

select ecode,count(*)
from
    (select distinct tcode,ecode
    from  @t group by tcode,ecode) t
group by ecode

它返回以下内容:

ecode tcode
1       3 (there are 3 distinct tcode for ecode of 1)
2       2 (there are 2 distinct tcode for ecode of 2)
3       1 (there is 1 distinct tcode for ecode of 3)

(编辑:鹰潭站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读