0

我想从bannerstatclick表中有这些列(idBannerStats:整数,时间:时间戳,idCampaignBanner:char(36))的表格bannerstatclick中提取总点击时间(如按周或按月)。我想将最大时间计算为当前日期,然后在 30 天日期之前计算,然后找到此日期范围之间的点击次数,它不会返回任何输出...

   SELECT count(idCampaignBanner) AS TotalClicks 
   FROM newradium.BannerStatsClick 
   WHERE Time BETWEEN   
   (Select max(`Time`) FROM newradium.BannerStatsClick)
  And
   (select max(`Time`)- INTERVAL 30 DAY FROM newradium.BannerStatsClick);
4

2 回答 2

0

试试这个

set @max_time:= (SELECT  max(`Time`) FROM newradium.BannerStatsClick );

SELECT count(idCampaignBanner) AS TotalClicks 
   FROM newradium.BannerStatsClick 
   WHERE Time BETWEEN date_add(@max_time, INTERVAL 30 DAY) and @max_time;
于 2013-11-06T06:14:14.820 回答
0
set @max_time:= (SELECT  max(`Time`) FROM newradium.BannerStatsClick );

SELECT count(idCampaignBanner) AS TotalClicks 
   FROM newradium.BannerStatsClick 
   WHERE Time BETWEEN  dateadd(day,-30,@max_time) and @max_time 
于 2013-11-06T06:16:54.740 回答