DISTINCT查询有问题吗? [英] Problem with DISTINCT query ?

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

问题描述

Hello Folks,

任何人都可以告诉我如何做以下非常简单的事情:

我有一张表说明了部门,部门和单位< br $> b $ b组织和我想要做的是找到一个分区。一个

部门有很多部门,一个部门有很多部门。我认为

因此对该部门的SELECT DISTINCT查询是有意义的并且

将我的部门搜索条件放在WHERE上。当然,

不起作用,因为你需要where子句来引用

SELECT DISTINCT子句中的一个字段,如果我把字段放在那里它会使那个

也是不同的。我知道它一定很简单,但我不知道怎么做



Hello Folks,
can anybody tell me how to do the following very simple thing:
I have a table that has say departments, divisions and units of an
organisation and what i am trying to do is find a divison. One
department has many divisions, and one division many units. I am think
therefore a SELECT DISTINCT query on the division would make sense and
to put my search criteria for department on the WHERE. Of course that
doesnt work since you need the where clause to refer to a field in the
SELECT DISTINCT clause and if I put the field there it would make that
distinct as well. I know it must be simple but i acnnot figure out how
to do it.

推荐答案

In事实上我可以把标准放在WHERE中,即使它们没有出现在

的SELECT中(我只是在访问查询设计中尝试过)。那么为什么呢?当我在me.form.filter中完全相同时,
不起作用? (它是

不是filteron = true或引号)

In fact I can put the criteria in the WHERE even if they dont appear in
the SELECT (i just tried it in access Query design). Why then does it
not work when I put exactly the same in me.form.filter ??? (and it is
not the filteron = true or the quotation marks)


更准确地解决问题的权利:这是表格'的记录来源上的查询



SELECT DISTINCT tlkpLocationDirectory.chrL4Description FROM

tlkpLocationDirectory ORDER BY tlkpLocationDirectory.chrL4Description;


这里是有问题的代码:


Me.Form.FilterOn = False

strWhere ="(((tlkpLocationDirectory.chrL2Description)="""&

cboL2D.Value&""""&"))"

Me.Form.Filter = strWhere''此时所有过于敌意的进入

参数框出现并请求值

tlkpLocationDirectory .chrL2Description

Me.FilterOn = True

我做错了什么?我从查询设计中得到了查询,它是

运行。

Right to be more precise with the problem: here is the query
on the form''s record source:

SELECT DISTINCT tlkpLocationDirectory.chrL4Description FROM
tlkpLocationDirectory ORDER BY tlkpLocationDirectory.chrL4Description;

and here is the problematic code:

Me.Form.FilterOn = False
strWhere = "(((tlkpLocationDirectory.chrL2Description)="" " &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere ''at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDirectory.chrL2Description
Me.FilterOn = True
What did i do wrong? I got the query from the query design and it was
running.


问题是你的表单'的记录集不包含chrL2Description。


在您的另一篇帖子中,您说这可以在查询中使用。那是因为

查询的记录集是表格,所以它的任何字段都是可用的。在您的表单中,您已将记录集限制为单个字段,

并且这就是它所知道的全部内容。要使其工作,您必须在表单的记录集中包含

chrL2Description。该字段不需要在表单上显示
;但它确实需要采用'记录集'的形式。


HTH,


Rob


农民 < KN ****** @ gmail.com>在消息中写道

news:11 ********************** @ y43g2000cwc.googlegr oups.com ...
The problem is that your form''s recordset does not contain chrL2Description.

In another of your posts you say that this works in a query. That''s because
the recordset for the query is the table, and so any of its fields are
available. In your form, you''ve limited the recordset to a single field,
and that''s all that it knows about. To get it to work, you must include
chrL2Description in the form''s recordset. The field does not need to be
displayed on the form; but it does need to be in the form''s recordset.

HTH,

Rob

"Farmer" <kn******@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
更准确地解决问题的权利:这是表格'的记录来源上的查询

SELECT DISTINCT tlkpLocationDirectory.chrL4Description FROM
tlkpLocationDirectory ORDER BY tlkpLocationDirectory.chrL4Description;

这里是有问题的代码:

Me.Form.FilterOn = False
strWhere ="(((tlkpLocationDirectory.chrL2Description) ="""&
cboL2D.Value&""""&"))"
Me.Form.Filter = strWhere''at this point所有太过敌意的进入
参数框出现并请求值
tlkpLocationDirectory.chrL2Description
Me.FilterOn = True

我做错了什么?我从查询设计中得到了查询,它正在运行。
Right to be more precise with the problem: here is the query
on the form''s record source:

SELECT DISTINCT tlkpLocationDirectory.chrL4Description FROM
tlkpLocationDirectory ORDER BY tlkpLocationDirectory.chrL4Description;

and here is the problematic code:

Me.Form.FilterOn = False
strWhere = "(((tlkpLocationDirectory.chrL2Description)="" " &
cboL2D.Value & """" & "))"
Me.Form.Filter = strWhere ''at this point the all too hostile enter
parameter box comes up and requests the value of
tlkpLocationDirectory.chrL2Description
Me.FilterOn = True
What did i do wrong? I got the query from the query design and it was
running.



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

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