GROUP BY FUNCTION

GROUP BY FUNCTION

Post by hkadhi » Sun, 15 Dec 2002 11:26:01



hi all,
I am using access database, and in my table i have the following:
ID 'as PK
Price
Quantity
Description
i am displaying everything in a MSHFlex Grid and in my ADO (which is linked
to the Grid) I have this statement:
SELECT ID, Quantity, Price FROM Table1 GROUP BY ID ORDER BY ID it works fine
BUT
I want to add the Description field to my grid, because showing only the IDs
and price doesn't give my client the satisfaction of knowing the description
of each ID. I can get it to display if i don't choose the group by function.
Is there anyway i can display the Description field and still use the GROUP
BY function?
i've seen it done before but i don't know how

thank you in advanced

 
 
 

GROUP BY FUNCTION

Post by Tore » Tue, 24 Dec 2002 11:01:35


Your statement as is would produce a syntax error, because Quantity and
Price are not aggregate functions and not part of the Group By.

Group By allows you to calculate aggregates on those records that have
matching values for the columns in the GROUP BY clause.  Consider the
following data:

ID  Qty  Price
1    3      21
1    5      35
2    1      12

You can now do:

Select ID, Count(*) as Sales, Sum(Price)
From MyTable
Group By ID

and you will get:

1    2      56
2    1      12

You can NOT use the statement you specify.

HTH,
Tore.


Quote:> hi all,
> I am using access database, and in my table i have the following:
> ID 'as PK
> Price
> Quantity
> Description
> i am displaying everything in a MSHFlex Grid and in my ADO (which is
linked
> to the Grid) I have this statement:
> SELECT ID, Quantity, Price FROM Table1 GROUP BY ID ORDER BY ID it works
fine
> BUT
> I want to add the Description field to my grid, because showing only the
IDs
> and price doesn't give my client the satisfaction of knowing the
description
> of each ID. I can get it to display if i don't choose the group by
function.
> Is there anyway i can display the Description field and still use the
GROUP
> BY function?
> i've seen it done before but i don't know how

> thank you in advanced