[英]How do I use the WHERE clause to query data between two date ranges? - SQL
[英]how can i query where clause using between date in sphinx
我有這個查詢:
select * from tabel where last_purchase_categories = 'flight'
and last_purchase_date between '2016-10-23 11:06:47' and '2016-10-23 11:06:49';
它在獅身人面像中沒有用。 我使用mysql查詢瀏覽器進行全文搜索。 有誰知道如何在獅身人面像中使用日期格式?
我認為這是因為last_purchase_date的數據類型是字符串。 那就是為什么我不能在查詢之間使用
好吧,獅身人面像無法進行這樣的字符串比較,至少不能進行之間的比較(假設您在字符串屬性中具有日期)。 而且也沒有“ datetime” 屬性類型。
可以將日期放在簡單的數字屬性中,並進行比較。
Unix時間戳可能很方便,可以在sphinx配置文件中完成(使用mysql unix_timestamp()
函數)
sql_query = SELECT ..., UNIX_TIMESTAMP(last_purchase_date) AS last_purchase_date FROM ...
sql_attr_uint = last_purchase_date
然后查詢將是這樣的
select * from tabel where last_purchase_categories = 'flight'
and last_purchase_date between 1477217207 and 1477217209;
大多數編程語言都具有方便的功能,可以將日期轉換為時間戳。
讓我們嘗試一下
它會工作。
SELECT count(*) FROM `tabel`
where last_purchase_categories = 'flight' and
last_purchase_date between '2017-03-27 02:13:11' and '2017-03-27 02:13:20'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.