我有下一个sql代码
SELECT date,count(clics)
FROM advertising_clics
WHERE date > CURDATE() - INTERVAL 7 DAY
GROUP BY date
结果
date count(clics)
2015-08-29 4
2015-08-30 1
2015-08-31 1
2015-09-01 1
2015-09-02 1
但我希望结果是这个
date count(clics)
2015-08-29 4
2015-09-02 1
答案 0 :(得分:0)
尝试获取第一条记录和最后一条记录,并将结果union
作为
SELECT date,count(clics)
FROM advertising_clics
WHERE date > CURDATE() - INTERVAL 7 DAY
GROUP BY date
order by date
limit 1
union
SELECT date,count(clics)
FROM advertising_clics
WHERE date > CURDATE() - INTERVAL 7 DAY
GROUP BY date
order by date desc
limit 1