从 select 语句返回值



>我有这个查询字符串

  select a.name, a.address
  from table_main a
  where a.id=3345

对于此查询,我正在尝试添加 a.amount,如果它为 null 则返回零,如果不返回某个值,则返回零

 select a.name, a.addres, isnull(a.amount, 0) else 333
 from table_main a
 where a.id=3345

任何想法如何解决这个问题,以便如果 a.amount 为 null,它返回零(如果不是返回值),即 333谢谢

select a.name, a.addres,
      case when a.amount is null then 0 else 333 end amount 
 from table_main a
 wher a.id=3345

您可以使用case语句

select a.name, 
       a.addres,
       case when a.amount is null 
            then 0 
            else 333
       end as amount_check
from table_main a
wher a.id = 3345

试试这个(用例-时间语句)

select a.name, a.addres, case when a.amount is NULL then 0 else 333 end as Amount
from table_main a
wher a.id=3345

你需要在 CASE 语句中将其括起来

SELECT a.NAME,
   a.addres,
   CASE 
      WHEN a.amount IS NULL
         THEN 0
      ELSE 333
   END
FROM table_main a where a.id = 3345

试试这个:

select a.name, a.addres,
case when a.amount is null then 0 else 333 end
from table_main a where a.id=3345

最新更新