如何在多个col中找到Min值 [英] how to find the Min value among multiple col

查看:211
本文介绍了如何在多个col中找到Min值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的DB 3 col,我想找到一个单一的值,在所有这些解释如下:表名:MyTable

i have in my DB 3 col and i want to find a single value among all of them as explaind here: table name:MyTable

-----------------------------
--id-- col1-- col2-- col3-
-----------------------------
   1     200    300     400 
   2     100    150     300
   3     800    102     20
   4     80     80       0

col1 col2 col3 = 0,这是其中的最小值。
是可能的!

i want the result out of col1 col2 col3 to be = 0 , which is the min value among them. is it possible !!!!

我的尝试:

select Min(col1, col2 , col3) as Tablemin
from MyTable


推荐答案

ANSI SQL:

select min(col)
from
(
    select col1 [col] from MyTable
    union all
    select col2 from MyTable
    union all
    select col3 from MyTable
)t

这篇关于如何在多个col中找到Min值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆