如何在多个col中找到Min值

see*_*ker 3 sql database min

我在我的DB 3 col中,我想在所有这些中找到一个值作为explainind:table name:MyTable

-----------------------------
--id-- col1-- col2-- col3-
-----------------------------
   1     200    300     400 
   2     100    150     300
   3     800    102     20
   4     80     80       0
Run Code Online (Sandbox Code Playgroud)

我希望col1 col2 col3的结果为= 0,这是它们中的最小值.可能吗 !!!!

我的尝试:

select Min(col1, col2 , col3) as Tablemin
from MyTable
Run Code Online (Sandbox Code Playgroud)

Kir*_*huk 6

ANSI SQL:

select min(col)
from
(
    select col1 [col] from MyTable
    union all
    select col2 from MyTable
    union all
    select col3 from MyTable
)t
Run Code Online (Sandbox Code Playgroud)

  • 你可以只使用UNION,不需要UNION ALL. (2认同)