没有在第二列返回值时的Mysql情况

时间:2015-03-31 07:28:29

标签: mysql pivot case

它只返回EIA的值,而不是EIA 2

(
  case 
   when tc.name = 'EIA' then tor.value else null 
  end
) as EIA, 
(
  case 
   when tc.name = 'EIA 2' then tor.value else null 
  end
) as EIA2

这是表结构

测试执行的Tor值 EIA,EIA 2正面,正面

ID Name  EIA      EIA 2
1  John  POSITIVE no values??

2 个答案:

答案 0 :(得分:1)

试试这个:

(
  CASE 
   WHEN tc.name IS NULL THEN '' WHEN tc.name = 'EIA' THEN tor.value
  END
) as EIA, 
(
  CASE 
   WHEN tc.name IS NULL THEN '' WHEN tc.name = 'EIA 2' THEN tor.value
  END
) as EIA2

答案 1 :(得分:0)

(CASE
      WHEN tc.name = 'EIA' THEN tor.value
      WHEN tc.name = 'EIA 2' THEN tor.value
      ELSE NULL
  END)

OR

(CASE
      WHEN tc.name = 'EIA' THEN tor.value
 END) as EIA,
(CASE WHEN tc.name = 'EIA 2' THEN tor.value
  END) as EIA2