Depend in the exact query, you can do:
SELECT column1, x.c, column1-x.c
FROM table1, (... complicated subselect ...) as x;
The above may not work if they're correlated, so you can try:
SELECT column1, column2, column1-column2
FROM
(SELECT column1, (... complicated subselect ...) as column2
FROM table1);
Hope this helps,
On Tue, Feb 17, 2004 at 01:02:43PM +0100, Holger Marzen wrote:
Hi all,
if I have something like this:
SELECT column1,
(... complicated subselect ...),
column1 - (... same subselect as above ...)
FROM table1;
do I really have to rewrite the subselect a 2nd time if I need that
result in another column's expression?
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ If the Catholic church can survive the printing press, science fiction
will certainly weather the advent of bookwarez.
http://craphound.com/ebooksneitherenorbooks.txt - Cory Doctorow
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see
http://www.gnupg.org
iD8DBQFAMgd6Y5Twig3Ge+YRAuTFAKDKWtaonB+zOZIO+415Eo uziuPptACgq7is
xBSqRe0p0KpTz8/MrHnx8zQ=
=93WW
-----END PGP SIGNATURE-----