Hi Alvey,
How about posting any DDL constraints and some sample data in the
tables and then the expected output.
The actual SQL DDL and some INSERT statements would be great.
It really does cut down down on the bog work anyone taking the time to
answer your SQL question has to do, but the problem sounds interesting
so I'll give it a go.
Here's a go...
SELECT AlveysTable.Item, AlveysTable.Pin, AlveysTable.Incid
FROM AlveysTable
WHERE (AlveysTable.Incid/3) >
(SELECT DISTINCT AT.Incid
FROM AlveysTable AS AT
WHERE (AT.Incid=
(SELECT Max(AT3.Incid) AS MaxOfIncid
FROM AlveysTable AS AT3
WHERE AT3.Incid<
(SELECT max(Incid)
FROM AlveysTable as AT2
WHERE AT2.Item = AT3.Item)
AND AT3.Item = AT.Item
GROUP BY AT3.Item)) AND AT.Item =
AlveysTable.Item)
Given
ID Item Pin Incid
1 a 1234 4
2 a 1233 5
3 a 1232 88
4 b 1222 3
5 b 3333 4
6 b 3333 3
7 c 2345 2
8 c 4345 7
9 c 5433 22
as the base data returns
Item Pin Incid
a 1232 88
c 5433 22
inserting
10 c 6666 20
Returns only
Item Pin Incid
a 1232 88
However not sure if this is the desired output...
Regards,
Peter
al************@yahoo.com (Alvey Sidecast) wrote in message news:<ed**************************@posting.google. com>...
Win XP, Access 02:
I've got a largish table with three (relevant) fields; Item, PIN &
Incid.
What I'd like to accomplish in one SQL query (I can do it in a couple
but it's ugly. Also,the app is VBA free at present and I'd prefer to
keep it that way if poss.) is to select the Item & PIN combination
which has the highest incidence for each individual Item, but *only*
if that combination's Incid is 3 times higher than the second highest
PIN's Incid. Have been bashing away for hours at this without joy. Any
help would be much appreciated.
cheers
alvey