繁体   English   中英

如何将此SQL Server查询转换为Oracle

[英]how to convert this SQL Server query into Oracle

如何将下面的SQL Server查询转换为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 SQLFiddle: http ://sqlfiddle.com/#!4/7f7da/1 SQL Server小提琴: http ://sqlfiddle.com/#!3/7f7da/1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM