如何将此 SQL 服务器查询转换为 Oracle

how to convert this SQL Server query into Oracle

如何将下面的 Sql 服务器查询转换为 Oracle

SELECT
    totalRecords = (SELECT
                        COUNT(*) 
                    FROM
                        Finance
    )
    ,
    positiveAmt = SUM(positiveAmount),
    negativeAmt = SUM(negativeAmount) 
FROM
    Finance
select count(*), sum(positiveAmount), sum(negativeAmount)
  into totalRecords, positiveAmt, negativeAmt
  from Finance;

negativeAmt = SUM(negativeAmount) 是 Microsoft 定义列别名的非标准方式。

在 Oracle(以及几乎所有其他 DBMS)中,列别名写在应该是别名的列表达式之后,而不是在它前面。

因此您的查询变为:

SELECT COUNT(*) as totalRecords,
       SUM(positiveAmount) as positiveAmt, 
       SUM(negativeAmount) as negativeAmt
FROM Finance

AS 关键字是可选的,但我建议使用它以使事情更清楚。

Oracle SQL小提琴:http://sqlfiddle.com/#!4/7f7da/1 SQL 服务器 fiddle: http://sqlfiddle.com/#!3/7f7da/1