我正在尝试使用Access女士对值进行分类 [英] Am trying to categorise values using Ms Access

查看:36
本文介绍了我正在尝试使用Access女士对值进行分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Access女士将值归为三类;可以说(低于3500为低,从35,000到1,500,000为中,高于1,500,000则为高).请帮助我还是一个学习者

I am trying to categorise values using Ms Access into three categories; lets say (less than 3500 to be low, from 35000 to 1,500,000 to be middle and greater than 1,500,000 to be Upper). Please help I am still a learner

推荐答案

使用简单的查询向导创建一个包含所有所需字段的选择查询,然后在设计视图中将其打开,并添加一个新列并在此文本中输入(在方括号之间使用您的数字字段名称,我称之为数字")

Create a select query with all the fields you need using the simple query wizard, then open it in design view and add a new column and type in this text (use your numeric fields name between the square brackets, I called mine "number")

category: IIf([number]<3500,1,IIf([number]<1500000,2,3))

这将根据[number]字段的值返回值1(第一个条件为true),2(第二个条件为true)或3(第一和第二个条件为false).可以通过将数字替换为文本"值来返回文本值.

This will return the value 1 (the first condition is true),2 (the second condition is true) or 3 (first and second conditions were false) depending on the value of the [number] field. This could return a text value by replacing the numbers with "text" values.

category: IIf([number]<3500,"Low",IIf([number]<1500000,"Middle","Upper"))

然后您可以在需要此[类别]字段的任何地方使用此查询.添加更多类别只会使嵌套Iif更长.我使用了< (小于)而不是< =小于等于,请根据需要进行调整.我还用3500而不是35000作为低端和中端之间的差异数字.

This query can then be used wherever you need this [category] field. Adding more categories just makes the nested Iif longer. I used < (less than) rather than <= less than and equal, adjust as necessary. I also used 3500 rather than 35000 as the number for the difference between low and middle.

如果只需要一次,则可以在表单或表上添加与计算字段相同的信息,但是查询意味着您可以轻松地对其进行更改,并使更改反映在您使用的任何地方.

If you only need it once you could add this same information as a calculated field on a form or table but a query means you can easily change it and have the change reflected everywhere you use it.

使用switch语句而不是嵌套的iif(由Don George建议),字段定义将为

Using the switch statement instead of nested iif (as suggested by Don George) the field definition would be

category2: Switch([number]<3500,"Low",[number]<1500000,"Middle",[number]>=1500000,"Upper")

这篇关于我正在尝试使用Access女士对值进行分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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