I'm doing a small calculation in the select
statement of an sql query along the lines of this:
SELECT
(select sum(weighting)
from table1
where id = tablemain.id) *
(select sum(weighting)
from table2
where id = tablemain.id) as rating
from
tablemain
The problem I have is that one of these SUM
values should have an upper limit of 8,
e.g. if the SUM
of the weight columns comes to 10 it should only multiply by 8.
Does anybody have any ideas of how this could be done in the select
statement or if it's even feasible?
Thanks