如何在日期格式为时间戳的两个特定日期之间显示数据

时间:2015-01-16 00:25:26

标签: php mysql sql

我正在尝试在两个特定日期之间显示表中的数据,日期格式为时间戳。

此查询在没有日期的情况下正常工作。

 SELECT table1.username,COUNT(table2.userid) as total FROM table2  INNER JOIN table1 
ON table1.userid = table2.userid GROUP BY table1.username 
      ORDER BY COUNT(table2.userid) DESC 

我使用以下查询来获取两个特定日期之间的数据。但它没有显示任何内容

    SELECT table1.username,COUNT(table2.userid) as total FROM table2  
    WHERE table2.date between '2015-01-0' and '2015-01-30'  INNER JOIN table1 ON 
table1.userid = table2.userid GROUP BY table1.username 
      ORDER BY COUNT(table2.userid) DESC 

1 个答案:

答案 0 :(得分:0)

尝试

SELECT table1.username,COUNT(table2.userid) as total 
FROM table2  
INNER JOIN table1 ON table1.userid = table2.userid 
WHERE table2.date between '2015-01-0' and '2015-01-30'
GROUP BY table1.username 
  ORDER BY COUNT(table2.userid) DESC 

我猜我们在写连接之前不能使用where子句。