mysql过滤重复的记录,并按指定字段降序排列

1.筛选出包含指定字段的记录,过滤重复记录,并按 等级 降序排列

SELECT username,RoleName,MAX(`Level`),count(DISTINCT RoleName) FROM `log_level` GROUP BY RoleName ORDER BY MAX(`Level`) DESC;

 

 id    username    RoleName    Level   

1         aaaa               张一              30

2         aaaa               张一              20

3         bbbb               张二              30

4         abbb               张二              15

5         dddd               张四              19

6        cccc                张三              11

7         dddd               张四              28

 

2.筛选出指定时间段内的记录

SELECT * FROM `log_createrole` where logtime BETWEEN '2013-03-15 00:00:00' and '2013-03-15 23:59:59';

你可能感兴趣的:(编程之初)