[英]SQL Statement - condition within a condition?
I have a table where each record contains the time, represented by an hour column (int)
and a minute column (int)
.For example: 我有一个表,其中每个记录包含时间,由hour column (int)
和minute column (int)
。例如:
**records |hours| mins**
record1 | 15 | 30
record2 | 12 | 25
I want to write a statement where only the records ahead of the current time will be displayed. 我想写一个声明,只显示当前时间之前的记录。 So far, I have: 到目前为止,我有:
SELECT...
WHERE hours >= hour(current_time)
AND
mins >= minute(current_time)
AND...
But this doesn't work because it needs both the hours and mins to be greater than the current hours and minutes. 但这不起作用,因为它需要的小时和分钟都要大于当前的小时和分钟。 How do I write to that so that if the hours are the same, then the minutes are compared? 如何写入,以便如果小时数相同,则比较分钟?
Do something like this: 做这样的事情:
WHERE hours >= hour(current_time)
OR (hours = hour(current_time) AND mins >= minute(currentime))
就像是
Where hours * 60 + mins > hours(currentTime) * 60 + minute(currentTime)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.