1
我有一個查詢,我使用UNION從兩個表中獲取數據子句UNION SELECT,它顯示正確,但問題是當我需要選擇不同的日期間隔在此期間進行顯示的數據,有什麼恰巧它只需要一個where子句並將其應用於該單個SELECT部分而不是整個查詢。我需要這個來應用於wholle ......怎麼樣?聯合凡在MySQL查詢
SELECT
TICKETS.TICKETID AS TICKET_NO,
RECEIPTS.DATENEW AS DATENEW,
PAYMENTS.TOTAL AS MONEY,
CUSTOMERS.NAME AS CUSTOMER,
PAYMENTS.PAYMENT AS PAYMENT
FROM RECEIPTS
LEFT JOIN TICKETS ON RECEIPTS.ID = TICKETS.ID
LEFT JOIN PAYMENTS ON RECEIPTS.ID = PAYMENTS.RECEIPT
LEFT JOIN CUSTOMERS ON TICKETS.CUSTOMER = CUSTOMERS.ID
WHERE ?(QBF_FILTER)
UNION SELECT
ADJUSTMENTS.TICKET_NO AS TICKET_NO,
ADJUSTMENTS.DATE AS DATENEW,
ADJUSTMENTS.ADJUSTMENT_AMOUNT AS MONEY,
ADJUSTMENTS.CUSTOMER_NAME AS CUSTOMER,
ADJUSTMENTS.ADJUSTMENT_TYPE AS PAYMENT
FROM ADJUSTMENTS
LEFT JOIN CUSTOMERS ON CUSTOMERS.ID = ADJUSTMENTS.CUSTOMER_ID
WHERE ?(QBF_FILTER)
>>>>上面的查詢從UNICENTA開放源代碼項目,它使用文件.BS生成報告,當我把拍攝地點在兩個選擇部分條款會生成SQL語法錯誤,現在我上面討論的問題是我需要解決的,謝謝:|
此嵌套select語句仍然會產生相同的SQL語法錯誤,那就是我想要預防的! – Saqib
奇怪,我不知道什麼是你的WHERE子句傳遞的子選擇。你可以把這兩個看出來,看看它給你什麼? – StaticVoid
需要日期是DATENEW在這兩個選擇,如果我拿出兩個WHERE子句它給附近UNION SELECT SQL語法錯誤.. :( – Saqib