类似于:select * from tableA where addtime>='2015-10-20 00:00:00' and addtime<='2016-12-02 23:59:59'
SELECTaa.*, bb.VALUE
FROM
(
SELECT
NAME,
max(time) AS time
FROM
my_test
GROUP BY
NAME
) aa
LEFT JOIN (
SELECT
NAME,
time,
sum(VALUE) AS VALUE
FROM
my_test
GROUP BY
NAME,
time
) bb ON aa. NAME = bb. NAME
AND aa.time = bb.time
ps:写得有点复杂 (my_test 换成你自己的表名)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)