baidu_32457989
2015-12-10 04:28
采纳率: 43.1%
浏览 3.0k

求大神帮我写一条查询增量的sql语句

图片说明
图片说明

如图,我有这些字段,每天都会插入一些数据
我现在需要获取的内容是
今天的read,click数据,和今天的减昨天的差值,和aid,规则如图
求大神帮我写一个

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • MYcsdn_Frank 2015-12-10 09:36
    已采纳

    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

    机器没装SQL,脱手写的,你自己试试

    评论
    解决 无用
    打赏 举报
查看更多回答(4条)

相关推荐 更多相似问题