如图,我有这些字段,每天都会插入一些数据
我现在需要获取的内容是
今天的read,click数据,和今天的减昨天的差值,和aid,规则如图
求大神帮我写一个
SELECT
SUM(d.read_num) AS READ,
SUM(d.click_num) AS click,
SUM(d.read_num - t.read_num) AS diffREAD,
SUM(d.click_num - t.click_num) AS diffclick,
u.aid
FROM
tc_url AS u
LEFT JOIN tc_data AS d
ON d.uid = u.id
LEFT JOIN
(SELECT
_d.read_num,
_d.click_num,
_u.aid
FROM
tc_url AS _u
LEFT JOIN tc_data AS _d
ON _d.uid = _u.id
WHERE _u.createtime = '昨天') AS t
ON t.aid = u.aid
WHERE u.createtime = '今天'
GROUP BY u.aid
你自己试试
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。