简体   繁体   中英

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. 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.

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); instead use HAVING .

Also, I don't think date3 is going to be the number of seconds.

Also2, without a GROUP BY, you are either going to show one row or none.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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