![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
Something of this form: 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 theform above. INSERT INTO c SELECT * a.f AS f, * a.x * t.r AS x, * a.y * t.r AS y, * a.z * t.r AS z FROM a, (SELECT * * a.f AS f, * * a.r / b.r AS r * FROM a, b * WHERE a.g != "p" AND b.g = "p" and a.f = b.f) t WHERE t.f = a.f Does that make sense? Does SQL syntax require b to be listed in the outerFROM clause? |
#12
| |||
| |||
|
|
There is another way that this can be achieved. It is specifically advised against in the manual, but I have always found it to work. INSERT INTO c SELECT a.f AS f, a.x * (@tmp:=(a.r / b.r)) AS x, a.y * @tmp AS y, a.z * @tmp AS z FROM a JOIN b USING(f) WHERE a.g != "p" AND b.g = "p" |

#13
| |||
| |||
|
|
I don't know what your business is, but relying on undefined behavior can sometimes result in the termination of your contract. Or your life ![]() Yes, Axel, did you bother to read my whole post? |
![]() |
| Thread Tools | |
| Display Modes | |
| |