你好我需要一點幫助,編寫一個基於my_id,report_id基本上指出沒有相應的否定匹配數的行的sql語句。oracle sql如何獲得不匹配的積極記錄
下面是表格聲明,以便更好地解釋。
CREATE TABLE ."TEST"
("REPORT_ID" VARCHAR2(100 BYTE),
"AMOUNT" NUMBER(17,2),
"MY_ID" VARCHAR2(30 BYTE),
"FUND" VARCHAR2(20 BYTE),
"ORG" VARCHAR2(20 BYTE)
)
這裏是一些樣本數據
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('1',50,'910','100000','67120');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('1',-50,'910','100000','67130');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('1',100,'910','100000','67150');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('2',200,'910','100000','67130');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('2',-200,'910','100000','67120');
INSERT INTO TEST (REPORT_ID, AMOUNT, MY_ID, FUND, ORG) VALUES ('1', '40.17', '910', '100000', '67150')
INSERT INTO TEST (REPORT_ID, AMOUNT, MY_ID, FUND, ORG) VALUES ('1', '-40.17', '910', '100000', '67150')
INSERT INTO TEST (REPORT_ID, AMOUNT, MY_ID, FUND, ORG) VALUES ('1', '40.17', '910', '100000', '67150')
如果你創建表並仔細觀察
,你會發現,通過REPORT_ID和添加my_id最積極的數量有直接的負面量。另一方面,我需要通過my_id和report_id來確定那些沒有相應負值的正數。
預期的結果應該是這樣的
"REPORT_ID" "FUND" "MY_ID" "ORG" "AMOUNT"
"1" "100000" "910" "67150" "40.17"
"1" "100000" "910" "67150" "100"
任何想法如何能acomplish這一點。
編輯: 發佈了錯誤的輸出結果。只是爲了清楚基金和組織直到比賽結束後纔有意義。例如,如果我正在使用plsql寫這個,我會發現有多少缺點,然後我有多少個額外的比較每個加上金額的每個減去金額和刪除它們,然後我會留下任何加上沒有負金額。 我對此感到抱歉。希望這現在更清楚。一旦我擁有了所有的比賽,我應該只剩下積極的數額。
編輯:
additional inserts
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',71,'911','100000','67150');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',71,'911','100000','67120');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',71,'911','100000','67140');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',71,'911','100000','67130');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',71,'911','100000','67130');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',71,'911','100000','67130');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',-71,'911','100000','67150');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',-71,'911','100000','67150');
Insert into TEST (REPORT_ID,AMOUNT,MY_ID,FUND,ORG) values ('5',-71,'911','100000','67150');
非常令人耳目一新,所有的數據都可以在問題中使用!請你只是澄清爲什麼200會顯示在上面的輸出中,因爲有相應的-200行? – ChrisProsser
org呢?應該忽略? – mucio
回答以上2條評論,那麼人們可以給你一些問題。 – johnny