winning_bids.sql 1.0 KB

12345678910111213141516171819202122232425
  1. -- Copyright Materialize, Inc. and contributors. All rights reserved.
  2. --
  3. -- Licensed under the Apache License, Version 2.0 (the "License");
  4. -- you may not use this file except in compliance with the License.
  5. -- You may obtain a copy of the License in the LICENSE file at the
  6. -- root of this repository, or online at
  7. --
  8. -- http://www.apache.org/licenses/LICENSE-2.0
  9. --
  10. -- Unless required by applicable law or agreed to in writing, software
  11. -- distributed under the License is distributed on an "AS IS" BASIS,
  12. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. -- See the License for the specific language governing permissions and
  14. -- limitations under the License.
  15. {{ config(materialized='view', indexes=[{'columns': 'item'}, {'columns': 'buyer'}, {'columns': 'seller'}]) }}
  16. SELECT DISTINCT ON
  17. (auctions.id) bids.*,
  18. auctions.item,
  19. auctions.seller
  20. FROM {{ source('auction','auctions') }}
  21. JOIN {{ source('auction','bids') }} ON auctions.id = bids.auction_id
  22. WHERE bids.bid_time < auctions.end_time
  23. AND mz_now() >= auctions.end_time