BTW there is a space between table1 and GROUP
"Ben" <bs2k1@excite.com> wrote...
> I have a table that stores hours, minutes, seconds and quantity.
> I can find the quantity per hour by selecting hours and quantity
> and group by hours with a sum for the quantity.
I'm not clear about what each row would represent?
Does it possibly represent some elapsed time, which gives a specific
quantity?
Then I don't understand what you think the result of such queries would
give.
e.g. if you have records like this:
1 0 10
1 1 10
1 1 20
2 0 10
2 5 20
The result of the grouping you used above would give
1 40
2 30
Is that what you want?
> However if I want minutes I need to multiply the hours by
> 60 and add them to the minutes and then find the sum of the
[quoted text clipped - 9 lines]
> ERROR: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]
> Too few parameters. Expected 1.
Well, you can't GROUP by the aggregated function, as the GROUP BY is the
criteria on *how* to aggregate...
And I'm not sure why you're using SUM on the hours and minutes anyway if you
want to group by them. If you group by them, there will only be one row to
SUM anyway...
Here you have to choose what you want the result to be.
Either you want something that sums it all:
SELECT Sum((hours*60)+minutes) AS mins, Sum(quantity) AS quant
FROM table1;
Gives:
427 70
Or you want something that distinguish each "timeframe".
SELECT (hours*60+minutes) AS mins, Sum(quantity) AS quant
FROM table1
GROUP BY (hours*60+minutes);
...given the same records as above, you would get:
60 10
61 30
120 10
125 20
Is that what you want?
// Bjorn A
Ben - 27 Apr 2006 16:41 GMT
Perfect thanks. You got it with the second. I had just realised about
the two sums actually giving the total. Sorry to confuse the
situation.
Thanks!!
Ben.