A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Sequential Grouping



 
 
Thread Tools Display Modes
  #1  
Old March 11th, 2010, 10:34 PM posted to microsoft.public.access.queries
blobmiester via AccessMonster.com
external usenet poster
 
Posts: 3
Default Sequential Grouping

Hey all,

I have a column in a table that goes something like this:

1
2
3
5
6
7
8

And I want to group the sequential numbers together like this:

1 - 3 : Group 1
5 : Group 2
6 - 8 : Group 3

Is there any reasonable way this can be done?

Thank you in advance,

Ryan Leckey

--
Message posted via http://www.accessmonster.com

  #2  
Old March 11th, 2010, 10:35 PM posted to microsoft.public.access.queries
blobmiester via AccessMonster.com
external usenet poster
 
Posts: 3
Default Sequential Grouping

Just for clarifiaction, I meant:

1 - 3: Group 1
5 - 8: Group 2

and if there was a 10 at the bottom then like this

1 - 3 : Group 1
5 - 8 : Group 2
10 : Group 3

Thank you

--
Message posted via http://www.accessmonster.com

  #3  
Old March 11th, 2010, 11:26 PM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Sequential Grouping

On Thu, 11 Mar 2010 22:34:13 GMT, "blobmiester via AccessMonster.com"
u58685@uwe wrote:

Hey all,

I have a column in a table that goes something like this:

1
2
3
5
6
7
8

And I want to group the sequential numbers together like this:

1 - 3 : Group 1
5 : Group 2
6 - 8 : Group 3

Is there any reasonable way this can be done?

Thank you in advance,

Ryan Leckey


If the grouping is arbitrary (i.e. not something you can calculate with an
arithmatic expression), your best bet is to use a Ranges table like:

Ranges
RangeName primary key, text, e.g. "Group 1"
Lo number, matching your table
Hi ditto

You can then use a "Non equi Join" query to look up the rangename:

SELECT yourtable.somefields, Ranges.RangeName
FROM yourtable
INNER JOIN Ranges
ON Ranges.Lo = yourtable.columnname
AND Ranges.Hi = yourtable.columnname

--

John W. Vinson [MVP]
  #4  
Old March 11th, 2010, 11:41 PM posted to microsoft.public.access.queries
blobmiester via AccessMonster.com
external usenet poster
 
Posts: 3
Default Sequential Grouping

Let me try and clarify mo

Here is the actual data:

1 2002
1 2003
1 2004
1 2006
1 2008
1 2009
2 2002
2 2003
3 2004
3 2005

I don't know what the years will be. But if there is multiple years in a row
I would like to collapse them in a range (grouping).

So the table above would be come this:

1 2002 - 2004
1 2006
1 2008 - 2009
2 2002 - 2003
3 2004 - 2005

Is that clearer? Sorry, if I wasn't clear before.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...eries/201003/1

  #5  
Old March 12th, 2010, 02:13 AM posted to microsoft.public.access.queries
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Sequential Grouping

On Thu, 11 Mar 2010 23:41:15 GMT, "blobmiester via AccessMonster.com"
u58685@uwe wrote:

Let me try and clarify mo

Here is the actual data:

1 2002
1 2003
1 2004
1 2006
1 2008
1 2009
2 2002
2 2003
3 2004
3 2005

I don't know what the years will be. But if there is multiple years in a row
I would like to collapse them in a range (grouping).

So the table above would be come this:

1 2002 - 2004
1 2006
1 2008 - 2009
2 2002 - 2003
3 2004 - 2005

Is that clearer? Sorry, if I wasn't clear before.


Well, it's clearer and it's altogether a different and unrelated problem (you
might want to reread your initial post after clearing your mind of
preconceptions about the database)....

That's going to be difficult and will require some VBA code, I'd guess. You
will need to find all records for each ID (or whatever the 1, 2 field
represents), sort them in order, and step through looking for gaps in the
sequence.

What will you be doing with the result? Storing it in a Table, generating a
report, or what? What's the context?

--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:06 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.