sql - How to select sum of values in a given range from huge tables quickly (Derby) -
i got , b table like:
table a
a b mount a0 b0 0.0001 a0 b1 0.0002
table b
c d weight c0 d0 0.99998 c0 d1 0.99996
each table has 10,000 - 100000 records.
i want combination mount+weight >= 0.9998
, mount+weight <= 0.9999
, example:
a b c d sum a0 b0 c0 d0 0.9999 a0 b1 c0 d1 0.9998
but if takes lot of time when try these ways:
method 1
select b c d mount+weight a,b mount+weight >= 0.9998 , mount+weight <= 0.9999
a table have index of mount, b table have index of weight
method 2
create a+b
table, takes more time method 1.
is there ways improve?
try
select a, b, c, d, mount+weight mw a,b mount+weight between 0.9998 , 0.9999
this may produce different execution plan
edit: realised derby. not sure if between available in derby
Comments
Post a Comment