SQLite中的case语句给出了错误的结果

时间:2017-10-05 02:33:05

标签: sql sqlite

import RefreshListActions from './RefreshListActions'

export default (props) => (
    <List {...props}
        actions={<RefreshListActions refreshInterval="10000" />}
        >
        <Datagrid>
            ...
        </Datagrid>
    </List>
)

当我在SQLite中的表上打印结果时,输出如下

SELECT Protocol, case (Protocol) 
When TYPE = 1 then 'Peer' 
When TYPE = 2 then 'TCMP' 
When TYPE = 3 then 'ICMP' 
When TYPE = 4 then 'Jitter'
ELSE 'Unknown'
END as Name

From 
(
select 
Protocol from ProtocolDetails group by Protocol 
) 
as T

我的问题是为什么打印3和4的未知,我的案例陈述有什么问题?

1 个答案:

答案 0 :(得分:1)

您正在混合two types of case。尝试:

SELECT Protocol,
       (case When TYPE = 1 then 'Peer' 
             When TYPE = 2 then 'TCMP' 
             When TYPE = 3 then 'ICMP' 
             When TYPE = 4 then 'Jitter'
             else 'Unknown'
        end) as Name
From (select Protocol
      from ProtocolDetails
      group by Protocol 
     ) T;

您的布尔表达式正在被评估为数字。