Hi,
full reading in CZ language is here:
 
http://www.dbsvet.cz/view.php?cisloclanku=2004092901
 
The tricks is:
SELECT MIN((

  SELECT FIRST 1 edate 

    FROM Products 

    WHERE iddevice=1 

    PLAN (PRODUCTS ORDER PRODUCTSDEVCNT)

    ORDER BY iddevice, edate ))

  FROM Devices D
 
You have to create index on SITE and WorkDate.
 
Also, for speed up, I recomended to create a separate table for Sites and
use just integer in TSH.
 
In this case, SITES will be Devices table, and TSH is Products table in my
example.
eDate is WorkDate and idDevice is your side integer identification.
PRODUCTSDEVCNT is your index on idSite and WorkDate.
 
Slavek
 
Ing. Slavomir Skopalik
Executive Head
Elekt Labs s.r.o.
Collection and evaluation of data from machines and laboratories
by means of system MASA (http://www.elektlabs.cz/m2demo)
-----------------------------------------------------------------
Address:
Elekt Labs s.r.o.
Chaloupky 158
783 72 Velky Tynec
Czech Republic
---------------------------------------------------------------
Mobile: +420 724 207 851
icq:199 118 333
skype:skopaliks
e-mail:[email protected]
http://www.elektlabs.cz <http://www.elektlabs.cz/>  

 
 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Marcin Bury
Sent: Friday, May 03, 2013 11:22 AM
To: [email protected]
Subject: [firebird-support] Looking for advice on indexes


  

Hello All

I have following table named TSH:

ID INTEGER
SITE VARCHAR(50)
WORK_DATE DATE

each day there are 10 up to 15 records inserted with various sites.
The list of sites is quite limited and consists of around 50 items.

Then I have following query

SELECT SITE_ID, MAX(WORK_DATE)
FROM TSH
GROUP BY 1

to get the latest entry for each site

What indexes should I create to get this query as quickest as possible?
Currently I have around 5000 records in the table.

Thanks in advance
Marcin






[Non-text portions of this message have been removed]

Reply via email to