How do I get the MIN() of two fields in Postgres?

大城市里の小女人 提交于 2019-11-30 07:47:24
cagcowboy

LEAST(a, b):

The GREATEST and LEAST functions select the largest or smallest value from a list of any number of expressions. The expressions must all be convertible to a common data type, which will be the type of the result (see Section 10.5 for details). NULL values in the list are ignored. The result will be NULL only if all the expressions evaluate to NULL.

Note that GREATEST and LEAST are not in the SQL standard, but are a common extension. Some other databases make them return NULL if any argument is NULL, rather than only when all are NULL...

Bill Karwin

Here's the link to docs for the LEAST() function in PostgreSQL:

http://www.postgresql.org/docs/current/static/functions-conditional.html#AEN15582

Mohamed Aamir

You can get the answer by putting that data into a column like this:

SELECT name, MIN(score_a, score_b) as minimum_score
FROM table

Here, we are putting the minimum value among score_a and score_b and printing the same by storing that value in a column named minimum_score.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!