简体   繁体   English

比较mysql中的两个字段

[英]comparing two fields in mysql

is their any query to pick certain date between two time stamps?The Problem is these two times stamps are set in two diffrent fields 他们的任何查询来选择两个时间戳之间的某个日期吗?问题是这两个时间戳设置在两个不同的字段中 在此处输入图片说明

SELECT * FROM table WHERE fs_from > theDate AND fs_to < theDate;

我建议使用准备好的语句,并将日期对象插入查询中。

In my opinion you can try in this way (If I really understood your question) 我认为您可以通过这种方式尝试(如果我真的了解您的问题)

SELECT myFields FROM myTable 
     WHERE myCertainDate BETWEEN fs_from AND fs_to

Try this: 尝试这个:

SELECT * 
FROM table 
WHERE fs_from > 'some date' 
AND   fs_to <  'some other date'

Which date do you want? 您要几号? You can choose a random date by doing: 您可以通过以下方式选择一个随机日期:

select t.*,
       date_add(t.fs_from, interval cast(datediff(fs_to, fs_from) * rand() as int) day
               ) as ArbitraryDateBetweenTwoDates
from table t

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM