1
0

query21.sql 1003 B

1234567891011121314151617181920212223242526
  1. select *
  2. from(select w_warehouse_name
  3. ,i_item_id
  4. ,sum(case when (cast(d_date as date) < cast ('1998-04-08' as date))
  5. then inv_quantity_on_hand
  6. else 0 end) as inv_before
  7. ,sum(case when (cast(d_date as date) >= cast ('1998-04-08' as date))
  8. then inv_quantity_on_hand
  9. else 0 end) as inv_after
  10. from inventory
  11. ,warehouse
  12. ,item
  13. ,date_dim
  14. where i_current_price between 0.99 and 1.49
  15. and item.i_item_sk = inventory.inv_item_sk
  16. and inventory.inv_warehouse_sk = warehouse.w_warehouse_sk
  17. and inventory.inv_date_sk = date_dim.d_date_sk
  18. and d_date between '1998-03-09' and '1998-05-07'
  19. group by w_warehouse_name, i_item_id) x
  20. where (case when inv_before > 0
  21. then inv_after / inv_before
  22. else null
  23. end) between 2.0/3.0 and 3.0/2.0
  24. order by w_warehouse_name
  25. ,i_item_id
  26. limit 100;