简体   繁体   中英

SQL: Query entries where timestamp >= 30 days ago

My entries have timestamps like 1488446089, 1469525148 etc.

I am trying to get entries not older than 30 days. Another use case would be to get entries >= YEAR(2016)

Whats wrong with this query. It return all results an ignores the where clause

"SELECT DATE(FROM_UNIXTIME(createdTime)) AS ForDate,
          COUNT(*) AS NumPosts
          FROM  Posts
          WHERE DATE_SUB(from_unixtime(createdTime), INTERVAL 30 DAY)
          GROUP BY DATE(FROM_UNIXTIME(createdTime))
          ORDER BY ForDate"

seems you don't have a filter (yoy don't compare values) eg date_sub(...) >= DATE(FROM_UNIXTIME(createdTime))

"SELECT DATE(FROM_UNIXTIME(createdTime)) AS ForDate,
        COUNT(*) AS NumPosts
        FROM  Posts
 WHERE DATE_SUB(from_unixtime(createdTime), INTERVAL 30 DAY) >= DATE(FROM_UNIXTIME(createdTime))
        GROUP BY DATE(FROM_UNIXTIME(createdTime))
        ORDER BY ForDate"

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