![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Is there a way inside an insert select statement to re-use an intermediate value that is required in the computation of several columns? Or mus it be computed for anew for each column? |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
For each row, the variable would need a different value. That value wouldthen be used in the calculation of multiple columns. I can use SET within the INSERT SELECT in that way? |
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
|
INSERT INTO c SELECT a.f AS f, a.x * a.r / b.r AS x, a.y * a.r / b.r AS y, a.z * a.r / b.r AS z FROM a, b WHERE a.g != "p" AND b.g = "p" AND b.f = a.f It's actually more involved, but that is the essence. I would like to only calculate a.r / b.r once for each row. The real situation's calculations are sufficiently intensive that a subquery would be better than running the form above. |
#10
| |||
| |||
|
|
Dvd Avins <dvdavins (AT) pobox (DOT) com> wrote: INSERT INTO c SELECT a.f AS f, a.x * a.r / b.r AS x, a.y * a.r / b.r AS y, a.z * a.r / b.r AS z FROM a, b WHERE a.g != "p" AND b.g = "p" AND b.f = a.f It's actually more involved, but that is the essence. I would like to only calculate a.r / b.r once for each row. The real situation's calculations are sufficiently intensive that a subquery would be better than running the form above. This is rather pointless. CSE (common subexpression elimination) is a standard optimization and you should rely on the DBMS to make use of it. |
![]() |
| Thread Tools | |
| Display Modes | |
| |