Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 多查询日期范围_Sql_Oracle_Oracle11g - Fatal编程技术网

Sql 多查询日期范围

Sql 多查询日期范围,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,我每天都要运行多个查询,是否有办法为多个选择设置日期范围,而不是在每个选择中输入日期。我使用oracle sql developer来运行这些查询 下面是三个示例,但有十几个查询: select count(*)"Tall ord" from cr_ordpar inner join cr_palhis on cr_palhis.pikref = cr_ordpar.pikref inner join CR_LODHED_DESP on cr_lodhed_desp.ilodno = cr_or

我每天都要运行多个查询,是否有办法为多个选择设置日期范围,而不是在每个选择中输入日期。我使用oracle sql developer来运行这些查询

下面是三个示例,但有十几个查询:

select count(*)"Tall ord"
from cr_ordpar
inner join cr_palhis on cr_palhis.pikref = cr_ordpar.pikref
inner join CR_LODHED_DESP on cr_lodhed_desp.ilodno = cr_ordpar.ILODNO
where cr_palhis.hstdat between '24-nov-15 07:00' and '25-nov-15 07:00:00'
and hststs_str = 'Pallet Output From Racking'
and cr_palhis.palhgt = '2700'
order by cr_lodhed_desp.lodref;

select count(*)"Tall del"
from cr_palhis
where cr_palhis.hstdat between '24-nov-15 07:00' and '25-nov-15 07:00:00'
and hststs_str = 'Pallet Deleted'
and cr_palhis.palhgt = 2700
and cr_palhis.rakblk <> 510; 

select  count(*)"Tall ind"
from cr_palhis
where cr_palhis.hstdat between '24-nov-15 07:00' and '25-nov-15 07:00:00'
and hststs_str = 'Pallet Indexed'
and cr_palhis.PALHGT = '2700';

你的约会有很多问题

首先,“24-nov-15 07:00”不是日期,而是字符串。必须始终使用TO_DATE将文字显式转换为日期。此外,如果您没有提到NLS_DATE_语言,请记住,日期取决于NLS。NOV在其他语言中不一样

YY格式在很久以前就被认为是Y2K错误,全世界已经看到了摆脱它的努力。提及完整的YYYY或使用RR格式,但在实施之前要理解它

可以使用GROUPBY子句在单个查询中获取不同的计数。考虑到所有条件都保持不变

SELECT hststs_str,
  COUNT(*) cnt
FROM cr_ordpar
INNER JOIN cr_palhis
ON cr_palhis.pikref = cr_ordpar.pikref
INNER JOIN CR_LODHED_DESP
ON cr_lodhed_desp.ilodno = cr_ordpar.ILODNO
WHERE cr_palhis.hstdat 
BETWEEN TO_DATE('24-nov-2015 07:00','dd-mon-yyyy hh24:mi','nls_date_language=ENGLISH') 
AND     TO_DATE('25-nov-2015 07:00','dd-mon-yyyy hh24:mi','nls_date_language=ENGLISH')
AND hststs_str       IN( 'Pallet Output From Racking', 
                         'Pallet Deleted', 
                         'Pallet Indexed'
                       )
AND cr_palhis.palhgt  = '2700'
AND cr_palhis.rakblk <> 510
GROUP BY hststs_str
ORDER BY cnt;

“24-nov-15 07:00”不是日期,而是字符串。cr_palhis.hstdat的数据类型是什么?我的问题是如何操纵最终结果。它只是一个报告,还是我们需要将它传递给其他前端工具?
SELECT hststs_str,
  COUNT(*) cnt
FROM cr_ordpar
INNER JOIN cr_palhis
ON cr_palhis.pikref = cr_ordpar.pikref
INNER JOIN CR_LODHED_DESP
ON cr_lodhed_desp.ilodno = cr_ordpar.ILODNO
WHERE cr_palhis.hstdat 
BETWEEN TO_DATE('24-nov-2015 07:00','dd-mon-yyyy hh24:mi','nls_date_language=ENGLISH') 
AND     TO_DATE('25-nov-2015 07:00','dd-mon-yyyy hh24:mi','nls_date_language=ENGLISH')
AND hststs_str       IN( 'Pallet Output From Racking', 
                         'Pallet Deleted', 
                         'Pallet Indexed'
                       )
AND cr_palhis.palhgt  = '2700'
AND cr_palhis.rakblk <> 510
GROUP BY hststs_str
ORDER BY cnt;