sql语句:百分比+分组

时间:2023-01-08 23:22:13

 1.结果是百分比的    

concat(rtrim(CAST(count_show/count_into * 100 as decimal(10,2))),'%')

 

2.把同一个channel_id的count_into组合成起来。

GROUP_CONCAT(count_into ORDER BY add_time ASC) AS count_into ... group by channel_id

 

3.取得不同game_id的时间desc的各前三条数据(分组取前三条记录)

SELECT * FROM pk_server AS s LEFT JOIN pk_game AS g ON s.server_gid=g.`game_id` WHERE  server_status=1 AND (SELECT COUNT(*) FROM pk_server WHERE server_gid=s.`server_gid` AND server_opentime>s.`server_opentime` AND server_status=1)<3 

 



4.取出每组最新的记录

SELECT * FROM(SELECT * FROM hd_tmp_cardlog ORDER BY Logtime DESC) hd_tmp_cardlog GROUP BY Rolename ORDER BY Logtime DESC;