我有一個工作查詢,它使用「BETWEEN」在日期範圍內查找結果,我需要的僅僅是給定日期範圍之間的結果或相反結果。以下是下面的查詢。如何在MySQL查詢中使用BETWEEN的對立方式?
SELECT loanac.id, loanac.name, loanac.lacc, loanac.phone,
SUM(loantrans.in) as totalin, SUM(loantrans.out) as totalout
FROM loanac, loantrans
WHERE (loanac.lacc=loantrans.account)
AND (`loantrans`.`date` BETWEEN CAST('$range' AS DATE) AND CAST('$date' AS DATE))
GROUP BY loanac.lacc
HAVING SUM(IFNULL(`loantrans`.`out`,0)) > SUM(IFNULL(`loantrans`.`in`,0))
任何人都可以幫助我找到相反的結果或不具有相同條件的日期範圍之間的結果嗎?
詳細截圖在這裏:https://www.dropbox.com/sh/lgmop3zxqaf9mjy/AAAWVWjZXd8da9KDDOqz2ANla?dl=0
對不起,沒有工作,這裏是在細節https://www.dropbox.com/sh/lgmop3zxqaf9mjy/截圖AAAWVWjZXd8da9KDDOqz2ANla?dl = 0 – Machine 2014-09-27 08:54:42
該圖完全沒有幫助。你顯示lacc 975,976和loantrans 1010的記錄。這兩個片段根本不相關。 – 2014-09-29 14:48:34