mysql - 多個表格怎麼合併分組查詢,並依照日期排序?
为情所困
为情所困 2017-05-16 13:28:13
0
1
1125

目前四個不同的表單獨查詢求和每天的資料
請教如何合併查詢四組不同資料每一天的和首列按日期排序只取年月日

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    2   21 2   4    1    1       4
2017-05-03   16    8    8       16
2017-05-           4
2017-05-05   20    10   10        10        10       

为情所困
为情所困

全部回覆(1)
巴扎黑

mysql 注意是在不改表結構和類型的情況下

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板