获取昨天日期的最简单最佳方法是:
subdate(current_date, 1)
您的查询将是:
SELECt url as link, count(*) as timesExisted, sum(DateVisited between UNIX_TIMESTAMP(subdate(current_date, 1)) and UNIX_TIMESTAMP(current_date)) as timesVisitedYesterdayFROM mytableGROUP BY 1
出于好奇,
sum(condition)为您提供满足条件的行 数
的原因(否则将需要繁琐且冗长的
case语句)是因为在mysql中,布尔值是
1true还是
0false,因此对条件求和有效地计算了多少次这是真的。使用此模式可以整理您的SQL代码。



