I have a table with format below. And I also know the most common used sql on it, so my question is how to create index on my table thus this sql query can have best performance. Btw, my db is sybase ASE 12.5.
Table t: bu, name, date, score_a, score_b
SQL:
SELECT bu, name, max(score_a), max(score_b)
FROM
t
WHERE date > '20110101' AND date < '20110901'
GROUP BY bu, name
Thanks for any suggestions.
Basically you need to add indexes to fields used by WHERE and GROUP BY clause, so I'd go with code, bu and name. How to create an index:
CREATE INDEX index_name ON table_name (column_name);
In your case:
CREATE INDEX idate ON t (date);