什么样的循环? [英] What sort of loop?

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

问题描述

我有一个文件(70,000条记录),其中家庭成员由共享的家庭号码识别。每个家庭中有一个人(头)有职业。让我们说Farmer被分配1并且渔夫被分配2.


假设每个家庭的所有成员在经济上依赖于头我想要分配一个共同的价值所有。因此,如果家庭号码为375且Head'的值为2,那么我希望所有其他家庭成员都获得价值2.继续使用家庭号码376和值1等。


我是新手。我猜测代码将是下一个循环的某种类型,它将在记录集中获取Head的指定值,并且在家庭编号相同时执行,即将相同的值应用于所有其他在家里。然后循环接受下一个家庭号码?


任何指导都会非常感激。

解决方案

你的问题是什么感觉,但它有助于了解您目前拥有的信息。我假设你在表格中有个人的原始数据。为了理解这一点,您还需要一个字段来指定他们拥有的家庭编号。


您是否已经有一个单独的职业表,将Farmer与1和Fisherman联系起来2?如果没有,那么你将需要一个。我假设每个人的记录也会有一个代码来表明其职业。


实际上 - 你如何确定哪个人应被视为一个家庭的负责人?


似乎解决方案更可能是UPDATE查询的SQL而不是VBA中的任何复杂问题,但在我们可靠地建议之前,我们需要您提供更多信息。否则我们给出的任何建议都是基于假设,应尽可能避免。


是数据在原始表中,占用号外国字段将与包含Farmer的表相关,渔夫等。主表有一个名为HouseholdNumber的字段。主表中还有一个字段,用于记录占用者的状态,因此户主的编号为1.

我想查看按家庭编号分组的每组记录的方法并且将占有号码应用于当前仅适用于头部的所有人。

结果是可以计算出经济上依赖于捕鱼或耕作的人而不是家庭的数量。


谢谢。这是我们正确回答你的问题所需要的信息。


尽管你的要求重复略有不同,但似乎你可能会有些困惑实际需要。让我解释一下。


如果您只是想报告这些信息,那么SELECT查询就是必要的。如果这是您想要的,则无需更新基础表数据。您最初的问题是关于更新数据。可以这样做,但根据您的要求,这不是必要的,在后面的文章中有不同的解释。现在我假设这是你需要的,但如果你因任何原因需要更新数据,那么也可以实现。


所以,在外行中描述查询的条款:

你需要主表(我现在称之为[tblPerson]。)在查询中两次。曾经代表该人,并再次代表该人的户主。从那里你包括你需要的[tblPerson]的所有数据,但只包括来自户主的职业信息。你没有包含任何表名,所以你必须弄清楚我指的是什么,并将它们换成你用过的名字。

展开 | 选择 | Wrap | 行号

I have a file (70,000 records) in which family members are identified by shared Household Numbers. One person (Head) in each household has an occupation. Let''s say Farmer is assigned 1 and Fisherman is assigned 2.

Making an assumption that all members of each household are economically dependent on the Head I want to assign a common value to all. So, if the household number is 375 and the Head''s value is 2 then I want all of the other members of the household to be given the value 2. Move on to household number 376 and value 1 etc.

I''m a novice at this. I''m guessing that the code would be some sort of for next loop which would take the assigned value of the Head in the set of records and do while the household number is the same, i.e. Apply the same value to all of the others in the household. Then loop around to take on the next household number?

Any guidance would be much appreciated.

解决方案

Your question makes sense, but it would help to know what information you currently have. I would assume you have the raw data of individuals in a table. For this to make sense you''d also need a field that specifies which Household Number they have.

Do you already have a separate table of occupations which links Farmer with 1 and Fisherman with 2? If not then you will need one. I assume each person record would also have a code to indicate its occupation.

In real terms - how do you determine which person should be considered the head of a household?

It would seem that the solution is more likely to be the SQL of an UPDATE query than anything complicated in VBA, but we need more information from you before we can advise reliably. Otherwise any advice we give is based on assumptions and that should be avoided where possible.


Yes the data is in a raw table and the occupation number foreign field will be related to a table containing Farmer, Fisherman, etc. The main table has a field called HouseholdNumber. There is also a field in the main table that numbers the status of the occupants, so the head of household is number 1.
I would like a means of looking at each set of records grouped under household number and applying the occupation number to all of them that currenly is only applied to the head.
The result would be that the number of people rather than households that are economically dependent on fishing or farming could be calculated.


Thank you. That''s the information we need in order to answer your question properly.

Having also given a slightly different repetition of your requirements though, it seems there may some confusion as to what you actually need. Let me explain.

If you simply want to report on this information then a SELECT query is all that''s necessary. There''s no need to update the underlying table data if that''s what you want. Your original question was about updating the data. That can be done but isn''t necessary based on your requirement as explained differently in your later post. For now I''ll assume that this is what you require but if you need the data updated for any reason then that can also be achieved.

So, to describe the query in layman''s terms :
You need the main table (I''ll call it [tblPerson] for now.) in the query twice. Once to represent the person, and again to represent the head of the household for that person. From that you include all the data from [tblPerson] that you need but the occupation information only from the head of household. You''ve included no table names so you''ll have to work out what I''m referring to and switch them for whatever names you''ve used.

Expand|Select|Wrap|Line Numbers


这篇关于什么样的循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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