2016-05-03 75 views
0

這是OrientDb 2.1.4。使用date()函數的SQL查詢

以下查詢正常工作:

從SyncableHist選擇其中history_date < =日期( '2016年4月12日21點25分17秒', 'YYYY-MM-DD HH:MM:SS')

並按預期返回三條記錄,每條記錄的值爲history_date ='2016-04-12 21:25:17'。 history_date是DATETIME類型。

然而,這不返回任何記錄:

從SyncableHist

選擇其中history_date =日期( '2016年4月12日21時25分17秒', 'YYYY-MM-DD HH:MM:SS' )

任何想法???

謝謝!

+0

不熟習orientDb,但儘量投history_date像從SyncableHist'選擇其中日期(history_date, 'YYYY-MM-DD HH:MM:SS')=日期('2016年4月12日21:25:17','yyyy-MM-dd HH:mm:ss')'。 –

+0

不幸的是,這在OrientDb中不是一個有效的語法。謝謝你... – Barbara

+0

試試這個:'從SyncableHist中選擇where history_date.format('yyyy-MM-dd HH:mm:ss')='2016-04-12 21:25:17'' –

回答

1

將比較前的日期格式設置爲字符串。不知道爲什麼,但可能有一些額外的像毫秒或您的數據庫無法比較這兩種方式。

select from SyncableHist where history_date.format('yyyy-MM-dd HH:mm:ss') = '2016-04-12 21:25:17'

+0

但是,它仍然不能解釋爲什麼history_date <= date('2016-04-12 21:25:17','yyyy-MM-dd HH:mm:ss')的作品。此外,如果history_date上有索引,則由於history_date.format(),查詢不使用它。 – Barbara