参见英文答案 >
How to perform an IF…THEN in an SQL SELECT?21个
> SQL returning custom values based on query results2
在查询选择中,我想显示一个字段是否满足条件的结果.
> SQL returning custom values based on query results2
在查询选择中,我想显示一个字段是否满足条件的结果.
想象一下,我有一个叫做股票的表.这张表有一列,告诉我股票中每个物品的数量.
我想做的是这样的:
SELECT stock.name,IF (stock.quantity <20,"Buy urgent","There is enough") FROM stock
解决方法
尝试
Case
SELECT stock.name,CASE WHEN stock.quantity <20 THEN 'Buy urgent' ELSE 'There is enough' END FROM stock