mysql group by 组内排序 group by 原理

mysql group by 组内排序

 

SELECT * FROM (
SELECT MAX(id) AS t,wukong_uid, 1 AS tag FROM  toutiao_uid_gathered_wukong GROUP BY wukong_uid
UNION ALL
SELECT id AS t ,wukong_uid, 2 AS tag FROM toutiao_uid_gathered_wukong
) AS tab ORDER BY wukong_uid ASC , t ASC ;

 

验证group by原理 是否来源同一行数据

 

SELECT * FROM (
SELECT MAX(id) AS t,wukong_uid, 1 AS tag,time_script FROM xmt_star_helper_toutiao_uid_gathered_wukong GROUP BY wukong_uid
UNION ALL
SELECT id AS t ,wukong_uid, 2 AS tag,time_script FROM xmt_star_helper_toutiao_uid_gathered_wukong
) AS tab ORDER BY wukong_uid ASC , t ASC ;

 

 

 

 

5914 10301285240 2 1516248413
6563 10301285240 2 1516264338
6767 10301285240 2 1516264338
7774 10301285240 2 1516264338
7774 10301285240 1 1516193381
376 10499564112 2 1516193381
4565 10499564112 2 1516248413
5019 10499564112 2 1516248413
5534 10499564112 2 1516248413
6425 10499564112 2 1516264338
6879 10499564112 2 1516264338
7394 10499564112 2 1516264338
7977 10499564112 2 1516264338
7977 10499564112 1 1516193381
360 10818489841 2 1516193381
360 10818489841 1 1516193381

 

posted @ 2018-01-18 16:51  papering  阅读(355)  评论(0编辑  收藏  举报