My current query looks like this:
SELECT * FROM `Entrys` WHERE `Timestamp` > 1469308755 AND `Timestamp` < 1469308765 AND (`Exchange` = 1 OR `Exchange` = 2) AND `Market` = 1
For each timestamp-value
For each Exchange
For each Other-Exchange
Divide Exchanges price where type = 2 by Other-Exchanges price where type = 1
943.Price / 940.Price
944.Price / 939.Price
961.Price / 985.Price
962.Price / 957.Price
You need to use a
JOIN. A JOIN is useful when you want data from two different rows to be referenced in the same expression (either an expression in the WHERE clause or an expression in the select-list).
So you need to join a row to another row that satisfies these conditions:
When you're doing a self-join like this one, you must use table aliases. I will use "numerator" and "denominator" for the two rows.
SELECT numerator.timestamp, numerator.price / denominator.price AS spread FROM Entrys AS numerator JOIN Entries AS denominator ON numerator.timestamp=denominator.timestamp AND numerator.exchange <> denominator.exchange AND numerator.type = 2 AND denominator.type = 1;