Saya pikir Anda mencoba mengakses validFrom
dan validTo
dari kueri kasus dalam kondisi di mana. Jika demikian, Anda perlu memformat ulang kueri Anda.
SELECT t1.* FROM ( SELECT mPrice, aPrice,
CASE
WHEN validFrom < '2013-11-01'
THEN '2013-11-01'
ELSE validFrom END AS validFrom,
CASE
WHEN validTo > '2013-11-30'
THEN '2013-11-30'
ELSE validTo END AS validTo
FROM commission) t1
WHERE ((t1.validfrom BETWEEN '2013-11-01' AND '2013-11-30') OR (t1.validto BETWEEN '2013-11-01' AND '2013-11-30')) ORDER BY t1.validFrom
Tapi ini akan mengembalikan 3 hasil. Jika Anda perlu mendapatkan hasil yang diharapkan, maka Anda perlu menggunakan AND
kondisi alih-alih OR
.
Maka kueri Anda akan menjadi
SELECT t1.* FROM ( SELECT mPrice, aPrice,
CASE
WHEN validFrom < '2013-11-01'
THEN '2013-11-01'
ELSE validFrom END AS validFrom,
CASE
WHEN validTo > '2013-11-30'
THEN '2013-11-30'
ELSE validTo END AS validTo
FROM commission) t1
WHERE ((t1.validfrom BETWEEN '2013-11-01' AND '2013-11-30') AND (t1.validto BETWEEN '2013-11-01' AND '2013-11-30')) ORDER BY t1.validFrom