Mysql如果条件为两列

时间:2012-07-09 09:16:52

标签: mysql

我想在MYSQL中检查以下条件。请帮我找到以下条件的解决方案

条件:

If(fld_intime == null)
{
    'InMiss' 
}
else if(fld_outtime == null)
{
   'Outmiss'
}
else 
{
    'Present'
}

我如何使用select语句创建它。

5 个答案:

答案 0 :(得分:1)

SELECT IF(fld_intime IS NULL, 'InMiss', IF(fld_outtime IS NULL, 'Outmiss', 'Present'))

答案 1 :(得分:0)

你正在寻找这个:

select case when fld_intime is null 
            then 'InMiss'
            when fld_outtime  is null 
            then 'Outmiss'
            else 'Present'
       end as Remarks
from your_table

答案 2 :(得分:0)

SELECT CASE 
        WHEN fld_intime is null THEN 'InMiss'
        WHEN fld_outtime is null THEN 'OutMiss'
        ELSE 'Present'
    END AS fld_status  from yourtable

答案 3 :(得分:0)

编写sql examplee ..在where query

中使用Case语句
select 
      case when fld_intime is null then 'InMiss' 
           when fld_outtime is null then 'Outmiss' 
      else 'Present' end
from yourTable;

答案 4 :(得分:0)

试试这个::

Select 
 CASE

 WHEN fld_inTime is null
  THEN 'InMiss' 
WHEN fld_outTime is null
THEN 'outMiss' 
ELSE
'Present'
END
from table