查询Postgres - 相同的表比较日期

时间:2015-12-11 15:07:03

标签: sql postgresql select

我在同一个表中有2个查询,并且有以下列 代码 - 日期 - 项目 - 记录

我的第一个问题:

SELECT * FROM "TABLE" pt   
WHERE pt.Item IN (1,2,3)  
AND CAST(pt.Date AS DATE) between '2015/12/01' AND '2015/12/10'  
AND pt.Code  in (x,y)  
AND pt.Record > 60 

第二个查询等于第一个,但只有“代码”值不同。

 SELECT * FROM "TABLE" pt   
 WHERE pt.Item IN (1,2,3)  
 AND CAST(pt.Date AS DATE) between '2015/12/01' AND '2015/12/10'  
 AND pt.Code  in (a,b)  
 AND pt.Record > 60

我需要在一个查询中得到结果
像这样:

Item - DateFirstQuery - FirstDateGreaterThanFirstQueryDate  
1 - 2015-12-01 00:00:01 - 2015-12-01 00:00:02 (Next date from the first query in  the second query)  

开始和结束日期

0 个答案:

没有答案