我正在尝试运行一个选择查询,该查询将拉出所有计划在2300的meds作为日期范围。有没有办法可以将预定的日期/时间转换为一小时?这就是我到目前为止所做的:
SELECT DISTINCT USERCODE,
TRANSACTIONID,
ACTION,
TRANSACTIONHOUR,
SOURCE,
RXNUMBER,
DESCRIPTION,
MASTERPATIENTID,
FACILITYCODE,
ADMINISTRATIONTIME
FROM ( ABC.TL TL
INNER JOIN
ABC.S_VIEW S_VIEW
ON (TL.RXNUMBER = S_VIEW.RXNUMBER))
INNER JOIN
ABC.PV PATIENTVISIT
ON (TL.MASTERPATIENTID = PV.MASTERPATIENTID)
WHERE (TL.USERCODE NOT IN ('ABC'))
AND (TL.ACTION IN ('A', 'DC'))
AND (TL.TRANSACTIONHOUR BETWEEN to_date('2011-07-01 00:00:00', 'yyyy/mm/dd hh24:mi:ss') AND to_date('2011-09-30 23:59:59', 'yyyy/mm/dd hh24:mi:ss')
我希望查询在指定日期包含所有分配,但仅限于2300时。数据库是oracle 10g。
答案 0 :(得分:1)
首先,您已使用不同格式的日期字符串和不同格式的格式。使其保持一致。
试试这个:
SELECT DISTINCT USERCODE,
TRANSACTIONID,
ACTION,
TRANSACTIONHOUR,
SOURCE,
RXNUMBER,
DESCRIPTION,
MASTERPATIENTID,
FACILITYCODE,
ADMINISTRATIONTIME
FROM ( ABC.TL TL
INNER JOIN
ABC.S_VIEW S_VIEW
ON (TL.RXNUMBER = S_VIEW.RXNUMBER))
INNER JOIN
ABC.PV PATIENTVISIT
ON (TL.MASTERPATIENTID = PV.MASTERPATIENTID)
WHERE (TL.USERCODE NOT IN ('ABC'))
AND (TL.ACTION IN ('A', 'DC'))
AND (TL.TRANSACTIONHOUR BETWEEN to_date('2011/07/01 00:00:00', 'yyyy/mm/dd hh24:mi:ss') AND to_date('2011/09/30 23:59:59', 'yyyy/mm/dd hh24:mi:ss')
AND TO_CHAR(TL.TRANSACTIONHOUR, 'HH24MI') = '2300' --THIS IS THE NEW CONDITION