2012-07-09 41 views
0

我想在MYSQL中檢查以下條件。請幫我找到下面條件的解決方案Mysql如果條件爲兩列

條件:

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

如何創建這個使用select語句..

+0

其中'InMiss','OutMiss','Present'輸出? – 2012-07-09 09:21:33

回答

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 
+0

我認爲他正在尋找內聯IF/Switch語句。 – 2012-07-09 09:19:58

+0

我想創建一個名爲「Remarks」的新列,併爲每個列添加像這樣的'Inmiss'或'Present或outmiss – 2012-07-09 09:21:09

+0

可以給出示例代碼的備註。 – 2012-07-09 09:21:41

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 
1
SELECT IF(fld_intime IS NULL, 'InMiss', IF(fld_outtime IS NULL, 'Outmiss', 'Present')) 
0

寫作SQL examplee ..使用Case語句進行查詢哪裏

select 
     case when fld_intime is null then 'InMiss' 
      when fld_outtime is null then 'Outmiss' 
     else 'Present' end 
from yourTable; 
0

試試這個::

Select 
CASE 

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

我認爲這不是rom期望的。 – manurajhada 2012-07-09 09:24:41