Subject | Re: [!! SPAM] Re: [firebird-support] Sub Queries |
---|---|
Author | Jkoz |
Post date | 2008-07-09T04:43:03Z |
Helen Borrie wrote:
[snip...]
Hi Helen,
Thank you for your fast replay. You are correct. It was an oversite on
my side.
In the mean time I have found out an other way to do this using case
EG.
SELECT T1.CUSTCODE ,
SUM(CASE WHEN T1.INTDATE >= '2007-01-01' THEN T1.VOLUME ELSE 0 END)
SUM(CASE WHEN T1.INTDATE < '2007-01-01' THEN T1.VOLUME ELSE 0 END)
FROM TEST1 T1
WHERE T1.INTDATE <= '2007-03-31'
GROUP BY 1
Not very usefull probably as this seems to be slower than the subquery
you provided,
which I find odd since this can be optimized a lot easier to touch each
record in the set once
and calculate the sums as needed instead of fetching an extra recordset
in memory for each
record in the main query. My hypophesis of how this works is strictly
based on intuition only AKA
no knowledge of the inner workings of a DB what so ever, so any insight
on the issue would be very
welcome and very much appreciated.
I have discovered the derived tables in the doc folder as well, an inner
join there might help
to accomplish the same thing I haven't tried that yet though.
I need more testing with proper indexies before deciding which to use.
Thank you once more for your time. Appreciated.
Best Regards
Yannis.
[snip...]
Hi Helen,
Thank you for your fast replay. You are correct. It was an oversite on
my side.
In the mean time I have found out an other way to do this using case
EG.
SELECT T1.CUSTCODE ,
SUM(CASE WHEN T1.INTDATE >= '2007-01-01' THEN T1.VOLUME ELSE 0 END)
SUM(CASE WHEN T1.INTDATE < '2007-01-01' THEN T1.VOLUME ELSE 0 END)
FROM TEST1 T1
WHERE T1.INTDATE <= '2007-03-31'
GROUP BY 1
Not very usefull probably as this seems to be slower than the subquery
you provided,
which I find odd since this can be optimized a lot easier to touch each
record in the set once
and calculate the sums as needed instead of fetching an extra recordset
in memory for each
record in the main query. My hypophesis of how this works is strictly
based on intuition only AKA
no knowledge of the inner workings of a DB what so ever, so any insight
on the issue would be very
welcome and very much appreciated.
I have discovered the derived tables in the doc folder as well, an inner
join there might help
to accomplish the same thing I haven't tried that yet though.
I need more testing with proper indexies before deciding which to use.
Thank you once more for your time. Appreciated.
Best Regards
Yannis.