So I have this query, where I find packages that exceed the merchant threshold. My problem is that I don't want to include weekends on the count. So if my package is created on a Friday, and the threshold is 2 days. This query will return the package when I check for it on Monday since it counts weekends as well. Is there a way that I can exclude weekends?
Package.joins(:merchant).where( "packages.created_at + interval '1 day' * merchants.threshold < ?",Time.zone.now )
I tried
Package.joins(:merchant).where( "packages.created_at + interval '1 day' * merchants.threshold < ?",Time.zone.now ).where("extract(dow from packages.created_at) not in (6,0)")
but it does not wor
https://stackoverflow.com/questions/66575728/how-to-remove-weekends-from-ruby-query-using-postgres March 11, 2021 at 10:41AM
没有评论:
发表评论