1、 先排序再子查询
- SELECT * FROM (SELECT * FROm player_level_up_log ORDER BY date DESC) AS t GROUP BY t.pid;
2、 需要进行筛选查询
- SELECT pid,pname,MAX(currLv) FROM player_level_up_log GROUP BY pid;
3、如果需要多字段去重统计的话,怎么办呢?
可以使用concat字段进行连接然后在进行分组
- SELECT pid,pname,weaponType,quility,MAX(clutureLv) AS 最大等级,MAX(date) AS 最后操作时间, concat(pid, weaponType, quility) AS pidWeaponTypeQuility FROM superWeapon_log GROUP BY pidWeaponTypeQuility;
4、MySql用DATE_FORMAT截取DateTime字段的日期值,用 DATE_FORMAT 来格式化日期字段
- SELECT DATE_FORMAT(crt_time,'%Y-%m-%d') FROM ad_n_advertise_t
执行结果:
转 http://justdo2008.iteye.com/blog/2344722