Manoj Marathayil wrote: > Is there a better way > to write this query? > any help is appreciated. > > Query: > SELECT SUM(metric_diff) FROM snapshot_master WHERE snapshot_master.metric_id > = ? AND > snapshot_master.timestamp_id in (select timestamp_id from timestamp_master > where > server_timestamp >= ? AND server_timestamp <= ? and strftime(?, > server_timestamp, 'unixepoch') = > strftime(?, ?, 'unixepoch')); > > Format string may vary depending on context. > > Table schema: > CREATE TABLE [snapshot_master] ( > [timestamp_id] INTEGER NOT NULL, > [metric_id] INTEGER NOT NULL, > [metric_now] TEXT, > [metric_diff] TEXT, > PRIMARY KEY (metric_id, timestamp_id)) > > > CREATE TABLE [timestamp_master] ( > [timestamp_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, > [server_timestamp] INTEGER, > [server_start_time] INTEGER, > [server_uptime] INTEGER, > [server_uptime_diff] INTEGER, > [server_is_connected] INTEGER) >
It would help to add an index on server_timestamp in the timestamp_master table. create index server_timestamp_idx on timestamp_master(server_timestamp); HTH Dennis Cote _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users