Subject Re: [ib-support] Speed problem
Author Svein Erling Tysvær
>Some brackets missing and no 'PLAN'?

Seems complicated, but maybe one line with
PLAN(PLAN(PLAN(PLAN(PLAN(PLAN(PLAN( just scrolled off the window?

Your second plan seems simpler - and gave me one idea for possible
improvement:

SELECT T.ROOM
, COUNT (*) AS COUNTS
, MAX( T.PREVIOUS ) AS MAXTIME
, SUM( T.PREVIOUS ) AS SUMTIME
, ( SELECT COUNT (*) FROM TRANSACTIONS C1
WHERE C1.TICKET_REF BETWEEN :FROMD AND :TOD
AND C1.APPLET = T.APPLET
AND C1.PREVIOUS < R.X5
AND C1.ROOM = T.ROOM ) AS CNT1
, ( SELECT COUNT (*) FROM TRANSACTIONS C2
WHERE C2.TICKET_REF BETWEEN :FROMD AND :TOD
AND C2.APPLET = T.APPLET
AND C2.PREVIOUS >= R.X5
AND C2.PREVIOUS < R.X6
AND C2.ROOM = T.ROOM ) AS CNT2
, ( SELECT COUNT (*) FROM TRANSACTIONS C3
WHERE C3.TICKET_REF BETWEEN :FROMD AND :TOD
AND C3.APPLET = T.APPLET
AND C3.PREVIOUS >= R.X6
AND C3.ROOM = T.ROOM ) AS CNT3
, T.APPLET
FROM TRANSACTIONS T
LEFT JOIN ROOMSTAT R ON R.TERMINAL = T.ROOM
WHERE T.TICKET_REF BETWEEN :FROMD AND :TOD
GROUP BY T.APPLET, T.ROOM
ORDER BY T.APPLET DESC, T.ROOM

Does this give the right result, and is it any faster?

Set