How tö select a column?

Started by Egon Frerichabout 9 years ago3 messagesgeneral
Jump to latest
#1Egon Frerich
egon@frerich.eu

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have a table with two columns with type money. If column 'a' has an
amount > 0 then this amount is wanted else the amount from column 'b'.

How could I do this?

Thanks.

Egon

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBAgAGBQJYqHc9AAoJECc7nbY+bg5uvT0P/0d00WyZtRQdrldVCy11GEJN
UyYgOqktgURYWfurZYD0Q//ARFbdWn+kAl3Ifk8P23iRfzA+wZQ28qKrM5MODmtN
AVVuwTCKJG00lLriR9tzWnnbWNyFEjG4aZHfa7RsvIc27uoqyj19Hjr37mrxtvOI
j0GPpp/sH8KQqloyh7I26TzOlMlQcMf7gHRoLXC0JPwZWLTAYVjmVfKU2ZXSbkFB
cTHOv5hfZ3XHXFftMqJDTsGYp/nG7nTdPpIWV3L9uyP2dmiBlZNlbgQsEQkpsYx9
WHA8NK9TWU02io6KpEsA/yxxPnZDMYaezXlnaT4VYjXrJa7aM85c2whmqEXKSl8n
cy/9wG1w1MLR0HGheT+9MmzHMEQbXhCbIKH1vV+3KXIRu6cRmc5YfCMVykOsgC8A
Z6VufOBq0c2NVqeDUm7aKy2z89CxNvs88Ixz2O/+qeIGURjw2pSeWS7N2mN4W2Jh
Zwnr3GBJufREUM55W+ACdO1LPr3cFY9M1o+92rw+KUKFZ50DMz7mP8h50OzIHX3o
gl8cgu+OydmSSes5/BEWuQT7Q8dUpxEztgiR39wBhkGvsL9hldXVz6AC0T3x177u
5UJABse/6i1qViuq4HcZK9OQbkNECeKTTNpPJszd/S5hAKOnt4Vg/0kDUbwm1Qwj
Rj6uIKDRpSY/5kl36kX6
=6A2K
-----END PGP SIGNATURE-----

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Egon Frerich (#1)
Re: [GENERAL] How tö select a column?

On Sat, Feb 18, 2017 at 9:33 AM, Egon Frerich <egon@frerich.eu> wrote:

I have a table with two columns with type money. If column 'a' has an
amount > 0 then this amount is wanted else the amount from column 'b'.

https://www.postgresql.org/docs/9.6/static/functions-conditional.html

SELECT CASE WHEN a > 0 THEN a ELSE b END AS a_or_b FROM tbl​;

David J.

#3Gavan Schneider
galeel.pendari@bigpond.com
In reply to: Egon Frerich (#1)
Re: How tö select a column?

On 2/18/17 at 3:33 AM, Egon Frerich wrote:

I have a table with two columns with type money. If column 'a' has an
amount > 0 then this amount is wanted else the amount from column 'b'.

Examples in 4.2.14

SELECT CASE WHEN a > 0 THEN a ELSE b END FROM <money_table>
WHERE <whatever>;

Regards
Gavan Schneider

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general