Re: How do you find data in a range?
- From: Stefan Hoffmann <stefan.hoffmann@xxxxxxxxxx>
- Date: Wed, 24 Jan 2007 14:30:27 +0100
hi Rick,
Rick Tipton wrote:
I have 2 tables. 1st has 2 fields that will be used to look up in another table and retrieve a value in a range.
Table 1 Data - Priority - 2, Sales - $200.00You have an implicit range.
Table 2 Data - Priority - 2, Range - $0, Contacts - 0
Priority - 2, Range - $150, Contacts - 2
Priority - 2, Range - $500, Contacts - 4
Priority - 2, Range - $1000, Contacts - 8
Should return Contacts = 4
Using an explicit range it would be:
Table2: Data, Prio, RangeFromEx, RangeToInc, Contacts
SELECT T1.*, T2.*
FROM T1
INNER JOIN T2 ON T2.Prio = T1.Prio
AND T2.RangeFromEx > T1.Sales
AND T2.RangeToInc <= T1.Sales
I'm getting all rows above the expected value.
SELECT Table 1.Name, Table 1..Priority, Table 1.Sales, Table 2.Priority, Table 2.Range, Max(Table 2.Range) AS MaxOfRange, Table 2.Contacts
FROM Table 1 INNER JOIN Table 2 ON Table 1.Priority = Table 2.Priority
GROUP BY Table 1.Name, Table 1.Priority, Table 1.Sales, Table 2.Priority, Table 2.Range, Table 2.Contacts
HAVING (((Max(Table 2.Range))>=[Table 1]![Sales]));
SELECT TOP 1 T1.*, T2.*
FROM T1
INNER JOIN T2 ON T2.Prio = T1.Prio
AND T2.Range > T1.Sales
ORDER BY T2.Range
mfG
--> stefan <--
.
- Prev by Date: Re: How to continue a line without letting it auto wrap
- Next by Date: Re: How to know the login password ?
- Previous by thread: Re: How to continue a line without letting it auto wrap
- Next by thread: RE: Pass value into Query from Macro or Module
- Index(es):