我有 4 个查询要合并为一个以减少数据库调用。每个间隔列出该时间间隔的产品,并用于特定的子处理。
select * from product where add_time >= NOW() - INTERVAL '12 hour' (get product add the last 12h)
select * from product where add_time >= NOW() - INTERVAL '24 hour' (get product add the last 24h)
select * from product where add_time >= NOW() - INTERVAL '7 day' (get product add the last week)
select * from product where add_time >= NOW() - INTERVAL '30 day' (get product add the last month)
可能吗?查询会是什么样子以及如何访问每个组间隔(12 小时、24 小时、7 天、30 天)来处理结果?
PostgreSQL 9.5.12
如果必须,只需在客户端中执行即可。
但是如果你必须的话,你可以将其中的一些卸载到服务器,我想我不会,因为它主要是视图逻辑。
如果你真的想要,你也可以把它全部放在一个案例陈述中......