假設(shè)我們有一個(gè)表“Order123”,其中包含 ProductName、Quantity 和 OrderDate 列,如下 –
mysql> Select * from Order123; +-------------+----------+------------+ | ProductName | Quantity | OrderDate | +-------------+----------+------------+ | A | 100 | 2017-05-25 | | B | 105 | 2017-05-25 | | C | 55 | 2017-05-25 | | D | 250 | 2017-05-26 | | E | 500 | 2017-05-26 | | F | 500 | 2017-05-26 | | G | 500 | 2017-05-27 | | H | 1000 | 2017-05-27 | +-------------+----------+------------+ 8 rows in set (0.00 sec)
登錄后復(fù)制
現(xiàn)在,如果我們想搜索在特定日期(例如 2017 年 6 月 25 日)收到的訂單數(shù)量,則可以按如下方式完成 –
mysql> Select ProductName, Quantity from Order123 where OrderDate = '2017-05-25'; +-------------+----------+ | ProductName | Quantity | +-------------+----------+ | A | 100 | | B | 105 | | C | 55 | +-------------+----------+ 3 rows in set (0.00 sec)
登錄后復(fù)制
假設(shè)我們也存儲(chǔ)了 OrderDate 和時(shí)間,那么借助以下查詢,我們可以獲得指定的輸出 –
mysql> Select ProductName, Quantity from Order123 where date(OrderDate) = '2017-05-25';
登錄后復(fù)制
以上就是如何在MySQL表中按日期搜索記錄?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!