Mysql 如何操作SQL查询输出
我想知道是否有可能,例如,我有一个sql表,其结果如下Mysql 如何操作SQL查询输出,mysql,sql,Mysql,Sql,我想知道是否有可能,例如,我有一个sql表,其结果如下 +----+---------+--------+--------+ | ID | Name | Number | Active | +----+---------+--------+--------+ | 1 | Jessica | 12 | 0 | | 2 | Andrew | 23 | 1 | | 3 | Jason | 53 | 0 | +----+------
+----+---------+--------+--------+
| ID | Name | Number | Active |
+----+---------+--------+--------+
| 1 | Jessica | 12 | 0 |
| 2 | Andrew | 23 | 1 |
| 3 | Jason | 53 | 0 |
+----+---------+--------+--------+
我想将活动字段更改为0=No
|1=Yes
,但仅在结果中,我不想更改行的值,是否可以进行一次查询
有了下面的答案,我成功地改变了它,但是现在我如何在php中响应这个值呢
SELECT *, case when Active =0 then 'No' when Active =1 then 'Yes' end as Expr1,
FROM table
它应该是这样的:$isActive=$rows['Expr1']代码>
NVM上面的行正在工作。只需使用case语句来翻译1=yes和0=No,就像这样
select ID
,Name
,Number
,case when Active=0 then 'No'
when Active=1 then 'Yes'
end as active_y_n
from table
只需使用case语句来翻译1=yes和0=No,如下所示
select ID
,Name
,Number
,case when Active=0 then 'No'
when Active=1 then 'Yes'
end as active_y_n
from table
使用时的用例
select Id,name,number,
case Active when 0 then 'No'
when 1 then 'Yes' end as active_status
from t
使用时的用例
select Id,name,number,
case Active when 0 then 'No'
when 1 then 'Yes' end as active_status
from t
一种特别简单的方法是使用elt()
:
一种特别简单的方法是使用elt()
:
选择case Active when 1,然后选择'Yes'else'No'
选择case Active when 1,然后选择'Yes'else'No'
例如,如果我想在PHP中回显Yes或No,我必须使用varActive\u y\u n
?它是否类似于:$isActive=$rows['Active\u y\u n'代码>然后echo$isActive
例如,如果我想在PHP中回显Yes或no,我必须使用varactive\u y\u n
?它是否类似于:$isActive=$rows['active\u y\u n']代码>然后echo$isActive代码>