小编rec*_*bot的帖子

对范围内的每个日期运行复杂查询

我有一张订单表

   Column   |            Type             |                      Modifiers                      
------------+-----------------------------+-----------------------------------------------------
 id         | integer                     | not null default nextval('orders_id_seq'::regclass)
 client_id  | integer                     | not null
 start_date | date                        | not null
 end_date   | date                        | 
 order_type | character varying           | not null
Run Code Online (Sandbox Code Playgroud)

数据具有针对 client_id 的非重叠常规订单,并且偶尔会出现临时订单,当它们具有匹配的 client_id 时,会覆盖其 start_date 的常规订单。存在应用程序级别的限制,以防止相同类型的订单重叠。

 id | client_id | start_date |  end_date  | order_type 
----+-----------+------------+------------+------------
 17 |        11 | 2014-02-05 |            | standing
 18 |        15 | 2014-07-16 | 2015-07-19 | standing
 19 |        16 | 2015-04-01 |            | standing …
Run Code Online (Sandbox Code Playgroud)

postgresql join

9
推荐指数
1
解决办法
2124
查看次数

标签 统计

join ×1

postgresql ×1