MySQL根据条件在第二列中显示相应的值

时间:2017-12-04 11:26:03

标签: c# mysql asp.net

我在下面的结构中有数据表:

    CallNumber  | Duration
    1112            30
    1112            null
    1112            null
    1119            10
    1175            null
    1132            59
    1175            190

我想选择查询的结果为:

    CallNumber  | Duration
    1112            30
    1112            30
    1112            30
    1119            10
    1175            190
    1132            59
    1175            190

我不知道如何实现上述结果我正在使用MySQL数据库。

1 个答案:

答案 0 :(得分:0)

你可以使用sql代码:

select 
  t.CallNumber,
  if (Duration is null, (select Duration from test  where t.CallNumber = CallNumber and Duration is not null limit 1), Duration) as Duration 
from 
  test t