简体   繁体   English

在MYSQLI where子句中使用日期

[英]Using date in the where clause, MYSQLI

I have a column in my table called date, and I'm trying to get the maximum date, and the minimum date, before subtracting the minimum date from the maximum date to get the seconds in between them. 我的表中有一列称为date,在从最大日期减去最小日期以获取它们之间的秒数之前,我试图获取最大日期和最小日期。 Then I use the seconds to limit whether I want the row to be shown or not. 然后,我用几秒钟来限制是否要显示该行。 The problem is that I think I did this part wrong, and nothing is being selected even though it prints out date3 is bigger than 0, when not using the where clause. 问题是我认为我做错了这一部分,并且当不使用where子句时,即使输出的date3大于0,也没有选择任何内容。

SELECT min(date) as date1, max(date) as date2, 
(max(time)-min(time)) as date3 
FROM tableName where date3 > 0;

You cannot reference field aliases in WHERE clauses (unless they are from subqueries in the FROM); 您不能在WHERE子句中引用字段别名(除非它们来自FROM的子查询)。 instead use HAVING . 而是使用HAVING

Also, I don't think date3 is going to be the number of seconds. 另外,我认为date3不会是秒数。

Also2, without a GROUP BY, you are either going to show one row or none. Also2,没有GROUP BY,您将不显示一行。

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

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