SQL, selection records where 2 agregated fields are not equal 
Author Message
 SQL, selection records where 2 agregated fields are not equal

I figured out how to use a left outer join to get values in table 1 and any
matching records in table 2.  there are 4 fields. I know how to sum fields 3
and 4 by field 1 (ie select 1 sum(3) as s1 sum(4) as s2 form a order by 1
group by 1 into b).  

What I do not see how to do in this step is how to select only records where
sum(3) <> sum(4) in the above select.  I can do it in a subsequent select.

Can it be done?



Wed, 29 Oct 2003 01:20:34 GMT  
 SQL, selection records where 2 agregated fields are not equal
Claude,

The HAVING clause is applied after the other results so it's the perfect
place to examine the results of the SUMs.

SELECT .... ;
    FROM ... ;
    WHERE ... ;
    HAVING S1 <> S2
--

Cindy Winegarden

Microsoft Certified Professional, Visual FoxPro
Microsoft Visual FoxPro MVP



Quote:
> I figured out how to use a left outer join to get values in table 1 and
any
> matching records in table 2.  there are 4 fields. I know how to sum fields
3
> and 4 by field 1 (ie select 1 sum(3) as s1 sum(4) as s2 form a order by 1
> group by 1 into b).

> What I do not see how to do in this step is how to select only records
where
> sum(3) <> sum(4) in the above select.  I can do it in a subsequent select.

> Can it be done?



Wed, 29 Oct 2003 01:50:49 GMT  
 SQL, selection records where 2 agregated fields are not equal

Thanks, will try it (so much to learn, so little time to learn it)/

Quote:
>Claude,

>The HAVING clause is applied after the other results so it's the perfect
>place to examine the results of the SUMs.

>SELECT .... ;
>    FROM ... ;
>    WHERE ... ;
>    HAVING S1 <> S2
>--

>Cindy Winegarden

>Microsoft Certified Professional, Visual FoxPro
>Microsoft Visual FoxPro MVP




>> I figured out how to use a left outer join to get values in table 1 and
>any
>> matching records in table 2.  there are 4 fields. I know how to sum fields
>3
>> and 4 by field 1 (ie select 1 sum(3) as s1 sum(4) as s2 form a order by 1
>> group by 1 into b).

>> What I do not see how to do in this step is how to select only records
>where
>> sum(3) <> sum(4) in the above select.  I can do it in a subsequent select.

>> Can it be done?



Fri, 31 Oct 2003 20:58:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. SQL-Select Record no of table1 (table 2 for selection)

2. VFP6 Reports Non-Equal Values are Equal.

3. backspace not equal to backtab

4. Setting a Variable equal to a field(Code)

5. Record newly inserted into MS SQL Server not immediately available when reselecting

6. SQL SELECT not returning all records

7. fields of record do not chaange when clicking another page in the form

8. Field in record not reflecting changes made by spinner control

9. results: Filtering no-match record/field (SELECT-SQL)

10. Best method - selection list of ALL records

11. Competing record selection methods

12. Mult-user record selection?

 

 
Powered by phpBB® Forum Software