SQL Brain Teaser
From: Ian Bainbridge <bainbridge_i_at_perc03_at_bgers.co.uk>
Date: 1995/09/20
Message-ID: <43pm8d$2qr_at_atlas.bgers.co.uk>#1/1
Date: 1995/09/20
Message-ID: <43pm8d$2qr_at_atlas.bgers.co.uk>#1/1
Can anybody lend a hand to this brain teaser because I seem to have
developed brain death ?
I have a table Project_costs ( project_code, expenditure_code ......)
There are 1-n items per project_code,expenditure_code combination.
What I am trying to determine with one piece of SQL is the number of
different expenditure_codes per project_code and ultimately the maximum
of those counts returned.
I know I could do a select distinct of project_code and then loop for each project_code find the number of distinct occurences of expedniture_code and track the maximum of those myself but I just feel it should be possible in one pass.
Am I just off the planet today ?
Any/all help/suggestions gratefully received.
-- +--------------------------+-------------------------+-----------------------+Received on Wed Sep 20 1995 - 00:00:00 CEST
| Ian Bainbridge | bainbridge.i_at_bgers.co.uk|Phone: (44)191-216-0202|
| British Gas ERS | Newcastle Upon Tyne, UK | x2790 |
+--------------------------+-------------------------+-----------------------+