Guest User

Untitled

a guest
Jan 17th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. CREATE TABLE product_prices
  2. (
  3. ProductId UInt64,
  4. TrackedAt Date,
  5. Price Nullable(Decimal(6, 2))
  6. )
  7. ENGINE MergeTree() ORDER BY (ProductId, TrackedAt)
  8.  
  9. | ProductId | Price | TrackedAt |
  10. |:-----------|------------:|:------------:|
  11. | 1 | 20 | 2019-01-16 |
  12. | 1 | 19 | 2019-01-17 |
  13. | 2 | 5 | 2019-01-16 |
  14. | 2 | 7 | 2019-01-17 |
  15.  
  16. | ProductId |
  17. |:-----------|
  18. | 1 |
  19.  
  20. 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