0

我正在使用 MySQL。这是我的架构:

bannerstatclick(idBannerStats:整数,时间:时间戳,idCampaignBanner:char(36))

我正在尝试编写一个查询,通过在 idCampaignBanner 上使用计数来选择按月的总点击次数。这将不起作用,它将给出错误无效使用组功能。我也会尝试使用having子句,但它也不起作用......

SELECT count(idCampaignBanner) AS TotalClicks ,max(`Time`) AS maxdate,(min(`Time`) + INTERVAL 30 DAY)as monthly
FROM newradium.BannerStatsClick 
WHERE Time BETWEEN   max(`Time`)  AND (  max(`Time`)- INTERVAL 30 DAY)
4

2 回答 2

0

像这样的东西应该可以工作(group by如果你进行聚合,你需要子句)

select count(idCampaignBanner), MONTH(`Time`) as m
from newradium.BannerStatsClick
group by m
于 2013-11-05T10:39:10.827 回答
0
SELECT 
  count(idCampaignBanner) AS TotalClicks
, max(`Time`) AS maxdate
, (min(`Time`) + INTERVAL 30 DAY)as monthly
FROM newradium.BannerStatsClick 
WHERE Time <= (Select max(`Time`) FROM newradium.BannerStatsClick)
  And Time >= (Select max(`Time`) - INTERVAL 30 DAY FROM newradium.BannerStatsClick)

从技术上讲,可以摆脱“Time <= (Select max( Time) FROM newradium.BannerStatsClick)”,并不会真正影响选择。但是留着以防您将来需要不同的范围

于 2013-11-05T10:41:28.337 回答