Subject | Re: [firebird-support] Re: SQL question |
---|---|
Author | Jerome Bouvattier |
Post date | 2004-02-25T09:16:24Z |
Hello Svein,
Thanks. I hadn't thought to an "exists" clause. However, the range on
VALUEDATE needs to be present in both main and sub-selects to really return
the intended results (see below). Then, it takes 20s to run. As you said,
it's a LOT better that 1.40 min but still far from 240ms.
SELECT P.ID, P.PRODUCTID, P.OUTLETID, P.VALUEDATE, P.SALEPRICE,
P.FACING
FROM PRESENCE P
WHERE
(P.OUTLETID IN (112169, 112170, 112171, 112172, 112173, 112174, 112175)) and
(P.STATUS = 2) and
(P.VALUEDATE >= '2003-09-01') and <===
(P.VALUEDATE < '2003-11-01') and <===
not exists (
select 1 from presence p2 where P2.VALUEDATE > P.VALUEDATE and
P2.PRODUCTID = P.PRODUCTID and
(P2.OUTLETID = P.OUTLETID) and
(P2.VALUEDATE >= '2003-09-01') and
(P2.VALUEDATE < '2003-11-01') and
(P2.STATUS = 2))
order by P.PRODUCTID, P.OUTLETID, P.VALUEDATE
Regards.
--
Jerome
Thanks. I hadn't thought to an "exists" clause. However, the range on
VALUEDATE needs to be present in both main and sub-selects to really return
the intended results (see below). Then, it takes 20s to run. As you said,
it's a LOT better that 1.40 min but still far from 240ms.
SELECT P.ID, P.PRODUCTID, P.OUTLETID, P.VALUEDATE, P.SALEPRICE,
P.FACING
FROM PRESENCE P
WHERE
(P.OUTLETID IN (112169, 112170, 112171, 112172, 112173, 112174, 112175)) and
(P.STATUS = 2) and
(P.VALUEDATE >= '2003-09-01') and <===
(P.VALUEDATE < '2003-11-01') and <===
not exists (
select 1 from presence p2 where P2.VALUEDATE > P.VALUEDATE and
P2.PRODUCTID = P.PRODUCTID and
(P2.OUTLETID = P.OUTLETID) and
(P2.VALUEDATE >= '2003-09-01') and
(P2.VALUEDATE < '2003-11-01') and
(P2.STATUS = 2))
order by P.PRODUCTID, P.OUTLETID, P.VALUEDATE
Regards.
--
Jerome