如何在查询 return 结果时创建案例 table
How to create a case when query to return a result in a table
我有一个问题,因为我有两个由国家代码连接的表和 return 个具有不同键的表。问题是我有空白,因为这些项目没有添加国家代码,但它们有我想用来添加项目的货币。例如,When "WALUTA" = 'PLN' THEN 'A.CODE =' PL ' 但它不起作用。还有其他解决办法吗?
proc sql;
create table COREP_CR as
select distinct
a.DATA_DANYCH as REPORTING_DATE,
a.CRD_CCF,
b.Kod,
a.EXP_PIERWOTNA as EAD_PRE_CCF,
a.ID,
a.TYPE_ASSET,
a.Currency,
when (TYPE_ASSET) 'Futures' and (Currency) = 'PLN' then a.KOD = 'PLN'
end,
I got >ERROR 76-322: Syntax error, statement will be ignored.
>
from corep as a
left join _work.country_corep as b on a.Kraj=b.Kraj
Group by b.Kod, a.TYPE_ASSET, a.CRD_CCF, ORIGINAL_ASSET_CLASS, FINAL_ASSET_CLASS, PRODUCT_TYPE
;
QUIT;
在得到帮助后,我喜欢上了这个新列 _TEMP,但我想把这个结果放到列 Kod 中。
case 语句应如下所示:
case when a.TYPE_ASSET = 'Futures' and a.Currency = 'PLN' then 'PLN'
else b.KOD
end "KOD"
因此,当满足定义的条件时,现在 'virtual' 名为“KOD”的字段将返回为“PLN”,否则来自联接 table [=19] 的字段 KOD 的内容=] 将返回。
如果我理解正确你正在尝试做什么 - 如果在加入的 table b 中没有对应的行,请在该字段中添加其他内容,否则将由 [=21] 中的数据填充=],那么您的 select 应该如下所示:
select distinct
a.DATA_DANYCH as REPORTING_DATE,
a.CRD_CCF,
--b.Kod,
Case When a.TYPE_ASSET='Futures' And a.Currency='PLN' Then 'PLN' --IF criteria are met, let us returned PLN as Kod
Else b.KOD --OTHERWISE return the Kod from table b
End "Kod",
a.EXP_PIERWOTNA as EAD_PRE_CCF,
a.ID,
a.TYPE_ASSET,
a.Currency
from corep as a
left join _work.country_corep as b on a.Kraj=b.Kraj
Group by b.Kod, a.TYPE_ASSET, a.CRD_CCF, ORIGINAL_ASSET_CLASS, FINAL_ASSET_CLASS, PRODUCT_TYPE
;
我有一个问题,因为我有两个由国家代码连接的表和 return 个具有不同键的表。问题是我有空白,因为这些项目没有添加国家代码,但它们有我想用来添加项目的货币。例如,When "WALUTA" = 'PLN' THEN 'A.CODE =' PL ' 但它不起作用。还有其他解决办法吗?
proc sql;
create table COREP_CR as
select distinct
a.DATA_DANYCH as REPORTING_DATE,
a.CRD_CCF,
b.Kod,
a.EXP_PIERWOTNA as EAD_PRE_CCF,
a.ID,
a.TYPE_ASSET,
a.Currency,
when (TYPE_ASSET) 'Futures' and (Currency) = 'PLN' then a.KOD = 'PLN'
end,
I got >ERROR 76-322: Syntax error, statement will be ignored.
>
from corep as a
left join _work.country_corep as b on a.Kraj=b.Kraj
Group by b.Kod, a.TYPE_ASSET, a.CRD_CCF, ORIGINAL_ASSET_CLASS, FINAL_ASSET_CLASS, PRODUCT_TYPE
;
QUIT;
在得到帮助后,我喜欢上了这个新列 _TEMP,但我想把这个结果放到列 Kod 中。
case 语句应如下所示:
case when a.TYPE_ASSET = 'Futures' and a.Currency = 'PLN' then 'PLN'
else b.KOD
end "KOD"
因此,当满足定义的条件时,现在 'virtual' 名为“KOD”的字段将返回为“PLN”,否则来自联接 table [=19] 的字段 KOD 的内容=] 将返回。
如果我理解正确你正在尝试做什么 - 如果在加入的 table b 中没有对应的行,请在该字段中添加其他内容,否则将由 [=21] 中的数据填充=],那么您的 select 应该如下所示:
select distinct
a.DATA_DANYCH as REPORTING_DATE,
a.CRD_CCF,
--b.Kod,
Case When a.TYPE_ASSET='Futures' And a.Currency='PLN' Then 'PLN' --IF criteria are met, let us returned PLN as Kod
Else b.KOD --OTHERWISE return the Kod from table b
End "Kod",
a.EXP_PIERWOTNA as EAD_PRE_CCF,
a.ID,
a.TYPE_ASSET,
a.Currency
from corep as a
left join _work.country_corep as b on a.Kraj=b.Kraj
Group by b.Kod, a.TYPE_ASSET, a.CRD_CCF, ORIGINAL_ASSET_CLASS, FINAL_ASSET_CLASS, PRODUCT_TYPE
;