Skip to content

Instantly share code, notes, and snippets.

@ateneva
Last active December 30, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ateneva/1260ffa13621a59cbeb9a8ccb66b33d6 to your computer and use it in GitHub Desktop.
Save ateneva/1260ffa13621a59cbeb9a8ccb66b33d6 to your computer and use it in GitHub Desktop.
How can I compare values with SQL?
-----------------------------Vertica--------------------------------------------------------------------
select
greatest(5.5, 8.2, -8.2) as HighestValue, -- returns the higer number, taking the sign into account
least(5.5, 8.2, -8.2) as LowestValue -- returns the lower number, taking the sign into account
-----------------------------MySQL----------------------------------------------------------------------
select
greatest(5.5, 8.2, -8.2) as HighestValue, -- returns the higer number, taking the sign into account
least(5.5, 8.2, -8.2) as LowestValue -- returns the lower number, taking the sign into account
HighestValue |LowestValue |
-------------|------------|
8.2 |-8.2 |
-----------------------------PostgreSQL--------------------------------------------------------------------
select
greatest(5.5, 8.2, -8.2) as HighestValue, -- returns the higer number, taking the sign into account
least(5.5, 8.2, -8.2) as LowestValue -- returns the lower number, taking the sign into account
highestvalue |lowestvalue |
-------------|------------|
8.2 |-8.2 |
----------------------------SQL Server---------------------------------------------------------------------
select
max(MyValue) as HighestValue, -- returns the higer number, taking the sign into account
min(MyValue) as LowestValue -- returns the lower number, taking the sign into account
from (values (5.5), (8.2), (-8.2)) as a(MyValue)
HighestValue |LowestValue |
-------------|------------|
8.2 |-8.2 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment