2012-10-21 66 views
-2
SELECT 
t3.transaction_id, 
t3.transaction_no, 
t3.retrivel_ref_no, 
t3.transaction_type, 
t3.reversal_flag, 
t3.expires_on, 
t3.currency_code, 
t3.message_reason_code, 
t4.sales_person_id, 
t3.card_no, 
t3.transaction_amount, 
t3.transmission_date_time 
FROM TRANSACTION AS t4 
INNER JOIN 
( SELECT 
    t2.transaction_id, 
    t2.transaction_no, 
    t2.retrivel_ref_no, 
    t2.transaction_type, 
    t2.reversal_flag, 
    t2.transmission_date_time, 
    t2.transaction_amount, 
    t2.card_no, 
    t2.expires_on, 
    t2.currency_code, 
    t1.message_reason_code 
    FROM 
    ( SELECT* 
     FROM transaction_pci_details 
     WHERE message_reason_code LIKE '%OUT%'|| 
      message_reason_code LIKE '%FAILED%' 
    ) AS t1 
    INNER JOIN 
    ( 
     SELECT* 
     FROM transaction_pci_details 
     WHERE action_code LIKE '%REQ%' 
    ) AS t2 
    ON t1.transaction_no = t2.transaction_no  
) AS t3 
ON t4.transaction_id = t3.transaction_id; 

回答

1
(SELECT* FROM transaction_pci_details WHERE 
    message_reason_code LIKE '%OUT%'|| message_reason_code LIKE '%FAILED%') AS t1 
INNER JOIN 
(SELECT* FROM transaction_pci_details WHERE 
    action_code LIKE '%REQ%') AS t2 
ON t1.transaction_no = t2.transaction_no 

可以簡化爲

SELECT* FROM transaction_pci_details as t1, transaction_pci_details as t2 WHERE 
    (t1.message_reason_code LIKE '%OUT%'|| t1.message_reason_code LIKE '%FAILED%') 
    AND t2.action_code LIKE '%REQ%' 
    AND t1.transaction_no = t2.transaction_no 

沒有INNER_JOIN

也許你可以這樣擺脫其他INNER_JOIN

您還可以通過編寫SELECT通過書寫SELECT * FROM mytable

擺脫lisis