在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)/ 請(qǐng)問(wèn)mysql 這樣的查詢需要能否實(shí)現(xiàn)?

請(qǐng)問(wèn)mysql 這樣的查詢需要能否實(shí)現(xiàn)?

數(shù)據(jù)庫(kù)結(jié)構(gòu)
帖子積分增加的記錄表
id,tid,opint,create_time
1,1,1,1510390059
2,1,1,1510390059
3,1,3,1510390059
4,2,3,1510390059
5,2,5,1510390059
6,3,3,1510390059
7,3,2,1510390059
8,4,3,1510390059

類似這樣,

需求:
獲取create_time 為1小時(shí)內(nèi) piont增加最多的前3 的tid?

請(qǐng)問(wèn)能否實(shí)現(xiàn)?

回答
編輯回答
舊螢火
SELECT 
    tid
FROM
    record
WHERE
    create_time >= CURRENT_TIMESTAMP - 3600000
GROUP BY tid
ORDER BY SUM(point) DESC
LIMIT 3

如果用APIJSON,可以這樣請(qǐng)求:

{
    "[]": {
        "Record": {
            "@column": "tid",
            "create_time{}": ">=CURRENT_TIMESTAMP-3600000",
            "@group": "tid",
            "@order": "SUM(point)-"
        },
        "count": 3
    }
}

然后服務(wù)器會(huì)返回:

{
    "[]": [
        {
            "Record": {
                "tid": 82001
            }
        },
        {
            "Record": {
                "tid": 82002
            }
        },
        {
            "Record": {
                "tid": 82003
            }
        }
    ],
    "code": 200,
    "msg": "success"
}

可以提取出tid:

{
    "Record-tid[]": {
        "Record": {
            "@column": "tid",
            "create_time{}": ">=CURRENT_TIMESTAMP-3600000",
            "@group": "tid",
            "@order": "SUM(point)-"
        },
        "count": 3
    }
}

然后服務(wù)器會(huì)返回:

{
    "Record-tid[]": [
        82001,
        82002,
        82003
    ],
    "code": 200,
    "msg": "success"
}

一個(gè)可直接在線測(cè)試的demo:
http://39.108.143.172/

{
    "Comment-userId[]": {
        "Comment": {
            "@column": "userId",
            "date{}": ">=CURRENT_TIMESTAMP-3600000",
            "@group": "userId",
            "@order": "SUM(momentId)-"
        },
        "count": 3
    }
}

用APIJSON,后端不用寫接口和文檔,前端/客戶端 定制返回JSON的內(nèi)容和結(jié)構(gòu)^_^
https://github.com/TommyLemon...

2018年2月15日 21:41