sum(当-condition-然后计数else 0结束的情况)
SELECt SUM(case when $P{oneDayAgo} <= datetime then count else 0 end) as 'today', SUM(case when $P{oneWeekAgo} <= datetime then count else 0 end) as 'thisweek', SUM(count) as 'thismonth'FROM statisticsWHERe name = "test" AND $P{oneMonthAgo} <= datetime AND datetime <= $P{now}请注意,如果需要平均值,请确保将NULL替换为0。



