Answer the question
In order to leave comments, you need to log in
Database query?
Good day. db structure:
CREATE TABLE testTable (
id serial,
date int,
testField1 smallint,
testField2 real,
val smallint,
PRIMARY KEY(id)
);
SELECT SUM(val), testField1 FROM (
SELECT DISTINCT ON (testField1, testField2) testField1, testField2, val FROM testtable ORDER BY testField1, testField2, date DESC
) t1 GROUP BY testField1
SELECT SUM(val), testField1 FROM (
SELECT DISTINCT ON (testField1, testField2) testField1, testField2, val FROM testtable ORDER BY testField1, testField2, date DESC
) t1 where testField1 in (1,5,50,10,19) and testField2 in (5,8,10,13) GROUP BY testField1
CREATE INDEX testIndex on testtable (testField1, testField2, date desc)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question