开发者社区> 问答> 正文

查询增量的sql语句

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

展开
收起
吴孟桥 2016-06-15 16:51:58 8324 0
1 条回答
写回答
取消 提交回答
  • 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

    你自己试试

    2019-07-17 19:39:41
    赞同 展开评论 打赏
问答分类:
SQL
问答地址:
问答排行榜
最热
最新

相关电子书

更多
SQL Server 2017 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载