mysql - 多个表怎样合并分组查询,并按照日期排序?
为情所困
为情所困 2017-05-16 13:28:13
0
1
1088

目前四个不同的表 单独查询求和每天的数据
请教如何合并查询四组不同数据每一天的和 首列按日期排序只取年月日

SELECT
    DATE_FORMAT(createTime, '%Y-%m-%d') AS 日期,
    count(*) AS 注册人次
FROM
    tokenlog
WHERE createTime BETWEEN '2017-05-01' AND '2017-05-31'
GROUP BY
    DATE_FORMAT(createTime, '%Y-%m-%d')
ORDER BY
    createTime
===============================================
SELECT
    DATE_FORMAT(logTime, '%Y-%m-%d') AS 日期,
    count(*) AS 场次
FROM
    sumelog
WHERE logTime BETWEEN '2017-05-01' AND '2017-05-31'
GROUP BY
    DATE_FORMAT(logTime, '%Y-%m-%d')
ORDER BY
    logTime
===============================================
SELECT
    DATE_FORMAT(logTime, '%Y-%m-%d') AS 日期,
    Sum(sumelog.consume) AS 消耗金币
FROM
    sumelog
WHERE logTime BETWEEN '2017-05-01' AND '2017-05-31'
GROUP BY
    DATE_FORMAT(logTime, '%Y-%m-%d')
ORDER BY
    logTime
===============================================
SELECT
    DATE_FORMAT(endTime, '%Y-%m-%d') AS 日期,
    count(DISTINCT userId) AS 参加活动人次
FROM
    game_u
WHERE endTime BETWEEN '2017-05-01' AND '2017-05-31'
GROUP BY
    DATE_FORMAT(endTime, '%Y-%m-%d')
ORDER BY
    endTime

要求最终显示结果如下
 日期   注册人次  场次  消耗金币  参加活动人次
2017-05-01   8    2    2       8
2017-05-02   4    1    1       4
2017-05-03   16    8    8       16
2017-05-04   4    1    1       4
2017-05-05   20    10   10       20

为情所困
为情所困

全部回复(1)
巴扎黑

mysql 注意是在不改表结构和类型的情况下

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板