View Full Version : Multiplying grouped data


sajonara
12-12-2009, 02:41 AM
Hi,
I have a query with two columns: one is used as a grouping column and in second one i'd like to get the product of grouped data(numbers) within that column. Is there a possibility of multiplying
grouped data? (this is not an option among Sum, Avg, Min, Max and others offered). If not, is there some other way to do it?
Thanks

jdraw
12-12-2009, 04:28 AM
Hi,
I have a query with two columns: one is used as a grouping column and in second one i'd like to get the product of grouped data(numbers) within that column. Is there a possibility of multiplying
grouped data? (this is not an option among Sum, Avg, Min, Max and others offered). If not, is there some other way to do it?
Thanks

Please provide more info.
Query sql, table

sajonara
12-12-2009, 06:30 AM
sql is: SELECT Sheet1.[Vrsta VP], Sum(Sheet1.Kolicina) AS SumOfKolicina
FROM Sheet1
GROUP BY Sheet1.[Vrsta VP];

What I'd need is to get the Product of 'Kolicina' instead of Sum. So that for each of 'Vrsta VP' values it would return group product of 'Kolicina'

GalaxiomAtHome
12-12-2009, 01:32 PM
The product of all the values for that field in every record?
Perhaps the data could be structured differently to make this calculation more readily achievable.

sajonara
12-12-2009, 01:42 PM
First column is Text type, and second is Number. So if in text column I have let say Blue, Red and Violet and in Number column 10,4,15,5,20 and 10 and 4 are under Blue, I'd like to get product(40) - basicaly grouping by text and product within each group by number.

GalaxiomAtHome
12-12-2009, 01:55 PM
What is the maximum number of possible numerical values in a group?

sajonara
12-12-2009, 02:12 PM
hm, i guess maximum would be around 100 values

Brianwarnock
12-13-2009, 05:24 AM
I think that you would have to use code, reading a recordset sorted on the TEXT field and with the crudely expressed logic below, which is not pseudo programming.

Get 1st record
Loop1: Move record field to productfield
Loop2: Get next record
If new group or eof
Output record
If eof exit
Else goto loop1
Endif
Else productfield =record field*productfield
Endif
Goto loop2

Brian