Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE product_prices
- (
- ProductId UInt64,
- TrackedAt Date,
- Price Nullable(Decimal(6, 2))
- )
- ENGINE MergeTree() ORDER BY (ProductId, TrackedAt)
- | ProductId | Price | TrackedAt |
- |:-----------|------------:|:------------:|
- | 1 | 20 | 2019-01-16 |
- | 1 | 19 | 2019-01-17 |
- | 2 | 5 | 2019-01-16 |
- | 2 | 7 | 2019-01-17 |
- | ProductId |
- |:-----------|
- | 1 |
- select (argMax(Price, TrackedAt) - argMin(Price, TrackedAt)) from (select ProductId, Price, TrackedAt from product_prices where ProductId = 1000 order by TrackedAt DESC limit 2)
Add Comment
Please, Sign In to add comment