[英]SQL query to hide the result of a single cell based on the value of another cell
使用case
。 这就像用于选择列的if/else
。
select
gameId,
case
when inProgress = 0 then
null
else
answer
end as answer,
inProgress
from game
这将显示game
中的所有行,但如果inProgress = 0
则不会显示答案。
看一下 MySql 的 case 语句。 您不一定能够隐藏该列,但您可以在其中输入 N/A 或 -1 之类的值来显示您想要了解的内容。
SELECT gameId, inProgress, CASE when inProgress = 0 then -1 ELSE answer AS answer FROM game;
一种类似但更紧凑的case 表达式,您可以使用内联 if
select gameId, if(inProgress = 1, null, answer) Answer, InProgress
from game;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.