1

这是我需要更改为 SQLSERVER 2008 的示例 oracle 查询。基本上它从 table2 获取 scode 的描述,如果没有使用“case”的描述或 null 描述,则将其设为“unknown”。怎么做。

      select a.scode,b.description,a.amt,a.purid 
       from
      (select scode,ISNULL(SUM(AMOUNT),0) AS AMT,count(pur_ID)
       from table1
       where scode is not null 
       group by scode)A, table2 B  WHERE  A.SOURCE_CODE =+B.SOURCE
4

1 回答 1

0

试试这个(请注意我加入=):

Select A.Scode, A.Amt, A.Counts, IsNull(B.Description, 'Unknown') Descripton
From (
      select Scode, SOURCE_CODE, Isnull(sum(amount),0) as Amt, count(pur_ID) Counts
      from table1 
      where scode is not null 
      group by scode, SOURCE_CODE
    ) A left join  table2 B on A.SOURCE_CODE = B.SOURCE

根据评论编辑

Select A.Scode, Isnull(sum(A.amount),0) as Amt, 
      count(A.pur_ID) Counts, IsNull(Max(B.description), 'Unknown') description
From Table1 A Left Join Table2 B
        On A.SOURCE_CODE = B.SOURCE
Where A.Scode is not null 
Group by A.Scode
于 2013-10-25T15:56:09.240 回答