Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite中的Case语句给出错误的结果_Sql_Sqlite - Fatal编程技术网

SQLite中的Case语句给出错误的结果

SQLite中的Case语句给出错误的结果,sql,sqlite,Sql,Sqlite,当我在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

当我在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号打印了Unknown,我的案例陈述有什么问题吗?

你是在混音。尝试:

您的布尔表达式将作为数字计算

Protocol     Name

1            Peer
3            Unknown
4            Unknown
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;