如何在 SQL 中用 select 更改值?

How to change the value with a select in SQL?

我需要一个其他值而不是 FULL 和 NONE,但我必须在 select 中这样做。

SELECT Calendar_Month,Series,Cnt 
FROM T_Cust_Eom_n 
where TYP='REB'
  and Series='FULL' 
   or TYP='REB' 
  and Series='NONE'  
order by Series desc,Calendar_Month

无论如何我可以用 as 做这个吗?

问题:

WHERE 子句中有多个条件时,您应该使用 ()

解法:

使用 IN 改进了您的查询。您可以在 ():

中使用任何其他值
SELECT Calendar_Month,Series,Cnt 
FROM T_Cust_Eom_n 
where TYP='REB' 
  and Series IN ('FULL','NONE', 'ANOTHER_VALUE')
order by Series desc,Calendar_Month

这是你想要的:

SELECT Calendar_Month,
CASE WHEN Series = 'FULL'
    THEN 'YOUR_TEXT_FOR_FULL'
     WHEN Series = 'NONE'
    THEN 'YOUR_TEXT_FOR_NONE'
END
AS Series
,Cnt
FROM T_Cust_Eom_n 
WHERE (TYP='REB'and Series='FULL') OR (TYP='REB' and Series='NONE')  ORDER BY Series DESC,Calendar_Month