本文介绍了使用2个或更多保存查询的UNION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些一直关注我的帖子的人 - 他们都属于

a狗竞赛组织的数据库。


有三个班级狗可以参加:

NOVICE,OPEN和UTILITY。


我想为每个班级制作一份前十名平均分数的报告/>
每年。

起初我只有一个查询并使用TOP谓词得到顶部

10认为它会让我得到每年每堂课前十名。

我没有足够的测试数据来实际测试这一点(一年内每班只有三个分数

) 。所以我有点猜测。


然而,在考虑之后我发现我只会得到

前10名的结果记录。整个结果记录集。


所以...我创建了三个查询来选择TOP 10;每个班级一个。

现在我想合并或者联合这三个查询,以便我可以根据这个新的TOP 10 Union查询确定报告。


我试过寻求UNION的帮助但以下只是不会通过查询构建器获得




[qryTOP10NoviceAvg] UNION [qryTOP10OpenAvg] UNION [qryTOP10Utility]


每个查询都是单独工作的。


帮助!!!任何想法?


问候,

SueB


***通过Developersdex发送 ***

For those of you who have been following my posts - they all pertain to
a Dog Competition Organization''s Database.

There are three classes that the dogs can participate:
NOVICE, OPEN, and UTILITY.

I want to produce a report of the top 10 average scores for each class
for each year.
At first I had a single query and used the TOP predicate to get the top
10 thinking that it would get me the top 10 in each class in each year.
I don''t have enough test data to actually test this (only three scores
per class in one year)...so I was sort of guessing.

However, after thinking about it I figured out that I would only get the
top 10 resultant records out of the entire resultant recordset.

So ... I created three queries to select TOP 10; one for each class.
Now I want to "merge" or union these three queries so that I can base
the report off this new TOP 10 Union query.

I''ve tried looking for help on UNIONs but the following just won''t get
past the query builder:

[qryTOP10NoviceAvg] UNION [qryTOP10OpenAvg] UNION [qryTOP10Utility]

Each of these queries works individually.

HELP!!! Any ideas?

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***

推荐答案




尝试

从[qryTOP10NoviceAvg]中选择* UNION select * from [qryTOP10OpenAvg]

UNION select * from [qryTOP10Utility]





表[qryTOP10NoviceAvg] UNION表[qryTOP10OpenAvg] UNION表

[qryTOP10Utility]


对于您的测试,只有3条记录,请使用选择前2或1进行测试


-

[OO = 00 = OO]



Try
Select * from [qryTOP10NoviceAvg] UNION select * from [qryTOP10OpenAvg]
UNION select * from [qryTOP10Utility]

or

Table [qryTOP10NoviceAvg] UNION Table [qryTOP10OpenAvg] UNION table
[qryTOP10Utility]

For your testing, with only 3 records, test it using select top 2 or 1

--
[OO=00=OO]






你不应该首先使用单独的查询。


这样的事情会为每个

类别选择前0个结果......(如果
记录有相同的结果)。


SELECT A.CategoryID,A.Result

FROM tblResults A

WHERE(A.Result)在



SELECT TOP 10结果

来自tblResults B

WHERE A.CategoryID = B.CategoryID



-

问候,


布拉德利


基督徒的回应


这篇关于使用2个或更多保存查询的UNION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:33