473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

aggregate functions

Hi,

I have 3 columns, I wish to group by one of them, choose one with max(), and
wish for the 3rd column to be in the same row as the one in the 2nd column.

Eg.

1 a i
1 b ii
2 a v
2 c iv
2 b i
3 d iii
3 c vi

if I group by the first column, choose max() on the second column (picking
(1,b),(2,c),(3,d)) I want to choose column 3 from the same row

output should be

1 b ii
2 c iv
3 d iii

Hope that's clear enough! I don't want to group by the 3rd column also,
because that duplicates column 1.

Cheers,
Chris
Nov 12 '05 #1
3 3983
If you really must use Roman numerals here, you will have to teach Access
how to order these.

Create another table with 2 fields:
- RomanNumber (text)
- SortAs (Number)

You can then join this table in a query to your other one, and choose the
max related value.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Not Me" <su**@sumwhere.fake> wrote in message
news:bq**********@ucsnew1.ncl.ac.uk...

I have 3 columns, I wish to group by one of them, choose one with max(), and wish for the 3rd column to be in the same row as the one in the 2nd column.
Eg.

1 a i
1 b ii
2 a v
2 c iv
2 b i
3 d iii
3 c vi

if I group by the first column, choose max() on the second column (picking
(1,b),(2,c),(3,d)) I want to choose column 3 from the same row

output should be

1 b ii
2 c iv
3 d iii

Hope that's clear enough! I don't want to group by the 3rd column also,
because that duplicates column 1.

Nov 12 '05 #2
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:3f**********************@freenews.iinet.net.a u...
"Not Me" <su**@sumwhere.fake> wrote in message
news:bq**********@ucsnew1.ncl.ac.uk...
I have 3 columns, I wish to group by one of them, choose one with max(), and
wish for the 3rd column to be in the same row as the one in the 2nd

column.

Eg.

1 a i
1 b ii
2 a v
2 c iv
2 b i
3 d iii
3 c vi

if I group by the first column, choose max() on the second column (picking (1,b),(2,c),(3,d)) I want to choose column 3 from the same row

output should be

1 b ii
2 c iv
3 d iii

Hope that's clear enough! I don't want to group by the 3rd column also,
because that duplicates column 1.

If you really must use Roman numerals here, you will have to teach Access
how to order these.


Ah, sorry that was just an example, the information isn't really numbers,
letters and numerals!
Anyway, I don't want to do anything with the 3rd column, other than display
it (max is on 2nd column)
Nov 12 '05 #3
this worked for me, using your data sample
paste this is the sql-view of a query

SELECT a.id, b.maxF1 AS f1, a.f2
FROM table1 AS a, [SELECT id, Max(f1) AS MaxF1
FROM Table1
GROUP BY id]. AS b
WHERE (((a.id)=[b].[id]) AND ((a.f1)=[b].[maxF1]));
I just don't know why the design view can display it properly ?

the [SELECT ... ]. AS b creates a sub table (b) with the first 2
fields you want, and then I join it to the first table to get the
matching f2

"Not Me" <su**@sumwhere.fake> wrote in message news:<bq**********@ucsnew1.ncl.ac.uk>...
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:3f**********************@freenews.iinet.net.a u...
"Not Me" <su**@sumwhere.fake> wrote in message
news:bq**********@ucsnew1.ncl.ac.uk...
I have 3 columns, I wish to group by one of them, choose one with max(), and wish for the 3rd column to be in the same row as the one in the 2nd column.
Eg.

1 a i
1 b ii
2 a v
2 c iv
2 b i
3 d iii
3 c vi

if I group by the first column, choose max() on the second column (picking (1,b),(2,c),(3,d)) I want to choose column 3 from the same row

output should be

1 b ii
2 c iv
3 d iii

Hope that's clear enough! I don't want to group by the 3rd column also,
because that duplicates column 1.

If you really must use Roman numerals here, you will have to teach Access
how to order these.


Ah, sorry that was just an example, the information isn't really numbers,
letters and numerals!
Anyway, I don't want to do anything with the 3rd column, other than display
it (max is on 2nd column)

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ariel Jakobovits | last post by:
I have a table with 2 primary keys, one is a foreign key, the other is produced by a sequence. I want to SELECT query for one record that has a list of the sequence-produced values for all...
1
by: Job Lot | last post by:
Is it possible to use Aggregate functions with GROUP BY Clauses on DataTable. I have a DataTable with following values: Date Amount Int Balance 1/1/2004 5000.00 50.00 5050.00...
2
by: jc | last post by:
Hi. Just as we have AVG(COLUMN_NAME) and MAX(COLUMN_NAME) how can I write my own variation of a such a function. If I can appreciate how to do this, then I hopefully I can write a...
10
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to...
5
by: David Garamond | last post by:
What do people think of adding some more aggregate functions. These are the ones that MySQL has and PG doesn't: - STD/STDDEV - VARIANCE - BIT_OR - BIT_AND - GROUP_CONCAT (for strings, added...
3
by: S P Arif Sahari Wibowo | last post by:
Hi! I would like to make an editable continous form, where most fields will be from table A and editable, except 1-3 fields are a glimpse into table B and uneditable. Table A relate to table B...
8
by: jefftyzzer | last post by:
The current issue of "Oracle Magazine" has an article on creating custom aggregate functions, which naturally got me thinking about how to do this in DB2. I found some articles on creating...
5
by: Dean | last post by:
Has anyone toiled with creating/using alternate domain aggregate functions? I have been messing with that a little. The one recordsource I have been working indicates I get 20 to 40% savings in...
0
by: BillCo | last post by:
just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
5
by: BillCo | last post by:
I just wasted a long time figuring out this and I figure if I post it might save someone some pain! Jet (DAO) will allow you to to use nested aggregate functions like building blocks, e.g.: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.