database - Optimize SQL query for given Conditions -
i have query of form:
select sum(some_column) (table) if x else y b else z c ...
now in java code,i phone call query every different value(x,y,z,...),which returns me required sum.my objective calculate total sum values,i.e,
total = sum_for_x + sum_for_y + sum_for_z + ....
now,off course,i hitting db every such value,which costly.can optimize in 1 single query job me,hitting db 1 time ?
assuming interested in total sum , not in partial sums , conditions mutually exclusive, can this:
select sum(some_column) (table) (a) or (b) or (c) or ...
an other way (if conditions not mutually exclusive) be:
select sum(some_column) from(select sum(some_column) some_column (table) (a) union select sum(some_column) some_column (table) (b) union select sum(some_column) some_column (table) (c) -- union a.s.o. )
sql database oracle optimization
No comments:
Post a Comment