2017-07-17 68 views
-3
SELECT 
TC_TXN.BOOKING_REF_ID, 
TC_TXN.CREATION_TIME, 
IFNULL(MAN_REQ.SUB_COMPANY_CODE,"") AS "SUB_COMPANY_CODE", 
IFNULL(CONCAT('/',SUBSTRING_INDEX(SUB_COMP.BV_GROUP_FQN_NAME,'/',-1)),"") AS SUB_COMPANY_NAME, 
"Company" AS "BILL_TO", 
"" AS "REF", 
BV_ENUM.VALUE, 
MI_TXN.PRODUCT_CHARGES, 
IFNULL(TC_TXN.VENDOR_PAYABLE_AMOUNT,0) AS VENDOR_AMOUNT, 
IFNULL(MAN_REQ.TICKET_NO,(select TICKET_NO from TC_FLIGHTS_BOOK tfb join TC_TRANSACTION tcx on(tcx.TRANSACTION_ID=tfb.TRANSACTION_ID) join TC_FB_FARE_DETAILS tf on (tf.OID=tfb.OID) limit 1)) AS "TICKET_NO", 
IFNULL(TC_FB.SP_PNR_NO,IFNULL(MAN_REQ.PNR_NO,"")) AS "PNR_NO", 
MAN_REQ.TOUR_CODE, 
TC_TXN.TRANSACTION_ID, 
TC_TXN.REQUEST_ID, 
MAN_REQ.EMPLOYE_ID, 
"" AS "TCID" 







FROm TC_TRANSACTION TC_TXN 
    LEFT JOIN MANUAL_INVOICE_TRANSACTION MI_TXN ON (TC_TXN.TRANSACTION_ID = MI_TXN.TRANSACTION_ID) 
    LEFT JOIN MANUAL_INVOICE_REQUEST MAN_REQ ON (MAN_REQ.REQUEST_ID = MI_TXN.REQUEST_ID) 
     LEFT JOIN TCP_ORGANIZATION SUB_COMP ON (SUB_COMP.ORGANIZATION_ID = TC_TXN.CUSTOMER_CODE) 
     LEFT JOIN BV_ENUM_VALUES BV_ENUM ON (TC_TXN.BOOKING_TYPE = BV_ENUM.INT_CODE AND BV_ENUM.TYPE_NAME = 'BOOKING_TYPE') 
     LEFT JOIN TC_FB_FLIGHT_DETAILS TC_FB ON (TC_FB.OID=TC_TXN.OID) 

     WHERE 
    TC_TXN.CREATION_TIME>=? and TC_TXN.CREATION_TIME<= ? AND TC_TXN.CURRENT_BOOKING_STATUS=0 
GROUP BY TC_TXN.TRANSACTION_ID 

當我運行此查詢ticket_no列只有第一個數據被提取。剩餘列正在正確提取。我正在嘗試解決這個錯誤超過2天。 在此先感謝只有一個數據從sql獲取

+0

ticket_no字段的子查詢不是相關的,這意味着它將爲所有記錄返回相同的值。但我並不真正理解這個問題,所以我不能確定這是否是錯誤的原因。請以更明確的方式描述您的意思是「僅獲取第一筆數據」 – Shadow

+0

對於ticket_no值相同的每一行。 –

+0

請參閱https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-詢問 – Strawberry

回答

0

根據OP的評論(「對於每一行的ticket_no值是相同的」),問題是ticket_no字段的子查詢不是相關的。這意味着,它的價值不依賴於任何值從外部查詢:

... 
IFNULL(MAN_REQ.TICKET_NO,(select TICKET_NO from TC_FLIGHTS_BOOK tfb join TC_TRANSACTION tcx on(tcx.TRANSACTION_ID=tfb.TRANSACTION_ID) join TC_FB_FARE_DETAILS tf on (tf.OID=tfb.OID) limit 1)) AS "TICKET_NO", 
... 

這也意味着,MAN_REQ.TICKET_NO場總是空,這引出了一個問題,爲什麼它的存在擺在首位。

由於問題與數據有關,問題沒有描述表格如何關聯,也沒有提供任何示例數據,我無法提供確切的解決方案,只能指出根本原因。