English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Table: example
1) Query: select * from example

PRODUCT STATE SALES
TV IZC 100
PC IZC 290
CD AMH 450
TV TZC 750
PC NOR 375

2) Query: select product,state,sum(sales) from product group by state

Record# PRODUCT STATE SUM_SALES
1 CD AMH 450
2 PC IZC 390
3 PC NOR 375
4 TV TZC 750

3) Query: select product,state,sales from product group by state having sum(sales) > 390

Record# PRODUCT STATE SALES
1 CD AMH 450
2 PC IZC 290
3 TV TZC 750

Look the IInd record in the 3rd table, it unsatisfy the criteria...

Any one tell whatz d reason.

2007-02-02 17:26:21 · 3 answers · asked by Ramesh S 2 in Computers & Internet Programming & Design

3 answers

For the 3rd query I think you need

select product, state, sum(sales) from product group by state having sum(sales) > 390

2007-02-02 17:33:33 · answer #1 · answered by lotsofish 4 · 0 0

kind of obvious!!

Look at the 3rd query, you're displaying sales, but not the sales' sum!! sales sum for IZC is 390, I checked that out on the first query's data:

TV IZC 100
PC IZC 290

the second query sums the sales for every state and shows the sums of the sale, the second does it too but shows only the first record it found for the state's sales, NOT THE TOTAL SUM FOR THE SALES. 2nd and 3rd are the same basically, but limited by the 2nd query's SUM_SALES calculated column, you could have written the 2nd:
select product,state,sum(sales) from product group by state where sum(sales) > 390
that will show you the sales' sum.

Cheers.

2007-02-02 18:15:18 · answer #2 · answered by Julio M 3 · 0 0

The difference is that in the third query, only rows that have a summ sales value of greater than 390 will be returned.

2007-02-02 17:42:39 · answer #3 · answered by BigRez 6 · 0 0

fedest.com, questions and answers