1

我有一张如图所示的桌子

Amount      Debit      Credit    Description
------      -----      ------    -----------
275.00      275.00               Payroll
500.00                 500.00    Payroll
288.00      288.00               Payroll
500.00      500.00               Payroll
600.00      600.00               Payroll
988.00                 988.00    Payroll
600.00                 600.00    Payroll

我想从上面提到的表格中显示两个不同的数字,如下所示

Amount      Debit      Credit    Description
------      -----      ------    -----------
500.00                 500.00    Payroll
500.00      500.00               Payroll

Amount      Debit      Credit    Description
------      -----      ------    -----------
600.00      600.00               Payroll
600.00                 600.00    Payroll

现在,问题是这个查询的 Oracle SQL 是什么?

4

4 回答 4

1

尝试使用EXISTS.

SELECT  a.*
FROM    tableName a
WHERE   EXISTS
        (
            SELECT  1
            FROM    tableName b
            WHERE   a.Amount = b.Amount 
            GROUP   BY Amount
            HAVING  COUNT(AMOUNT) = 2 AND
                    COUNT(Debit) = 1 AND
                    COUNT(Credit) = 1
        )
于 2013-08-27T07:08:39.687 回答
0

select * from table where amount in(按金额从表组中选择金额,描述总和(借方,贷方)= 0)

但是最好使用任何 ID 列进行自我加入和分组(我相信您将在原始表中拥有)而不是数量。因为相同的金额可能会重复,但借方或贷方不等。

于 2013-08-27T07:10:02.240 回答
0

请试试:

SELECT
 Amount,
 Debit,
 Credit,
 Description
FROM
 YourTable
WHERE
 Amount IN (500.00, 600.00)
ORDER BY Amount
于 2013-08-27T07:02:17.350 回答
0

像这样

select amount,debit,credit,Description 
from tablename 
where amount = 500 and amount = 600 
group by amount,debit,credit,description;
于 2013-08-27T07:03:13.660 回答