1

我将 areal转换为 anint并将 afloat转换为 anint并像这样比较两者:

  where
  cast(a.[SUM(PAID_AMT)] as int)!=cast(b.PAID_AMT as int) 

但我仍然得到两者相等的结果。例如:

+-----------+-----------+------------+------------+----------+
|   accn    |  load_dt  |   pmtdt    | sumpaidamt | Bpaidamt |
+-----------+-----------+------------+------------+----------+
| A133312   | 6/7/2011  | 11/28/2011 | 98.39      | 98.39    |
| A445070   | 6/2/2011  | 9/22/2011  | 204.93     | 204.93   |
| A465606   | 5/19/2011 | 10/19/2011 | 560.79     | 560.79   |
| A508742   | 7/12/2011 | 10/19/2011 | 279.65     | 279.65   |
| A567730   | 5/27/2011 | 10/24/2011 | 212.76     | 212.76   |
| A617277   | 7/12/2011 | 10/12/2011 | 322.02     | 322.02   |
| A626384   | 6/16/2011 | 10/21/2011 | 415.84     | 415.84   |
| AA0000044 | 5/12/2011 | 5/23/2011  | 197.38     | 197.38   |
+-----------+-----------+------------+------------+----------+

这是完整的查询:

select 
  a.accn,
  a.load_dt,
  a.pmtdt,
  a.[SUM(PAID_AMT)] sumpaidamt,
  sum(b.paid_amt) Bpaidamt
  from
  [MILLENNIUM_DW_DEV].[dbo].[Millennium_Payment_Data_May2011_July2012] a
  join
  F_PAYOR_PAYMENTS_DAILY b
  on
  a.accn=b.ACCESSION_ID
  and
  a.final_rpt_dt=b.FINAL_REPORT_DATE
  and
  a.load_dt=b.LOAD_DATE
  and
  a.pmtdt=b.PAYMENT_DATE
  where
  cast(a.[SUM(PAID_AMT)] as int)!=cast(b.PAID_AMT as int) 

  group by 
    a.accn,

  a.load_dt,
  a.pmtdt,
  a.[SUM(PAID_AMT)]

我究竟做错了什么?我如何只返回不相等的记录?

4

2 回答 2

3

我不明白为什么会有问题。

该查询返回b ( sum (b.paid_amt) Bpaidamt) 中的付款总和。where 子句是比较个人付款。这只是意味着有不止一次的付款。

也许您的意图是使用 HAVING 子句:

having cast(a.[SUM(PAID_AMT)] as int)!=cast(sum(b.PAID_AMT) as int)
于 2012-08-09T22:03:53.023 回答
2

你可以做一个回合和一个演员声明。

cast(round(sumpaidamt,2) as money) <> cast(round(Bpaidamt,2) as money)

Sql Fiddle 展示了它是如何工作的http://sqlfiddle.com/#!3/4eb79/1

于 2012-08-13T11:29:37.563 回答