Heim  >  Artikel  >  Datenbank  >  mysql 复杂的查询语句,工作中用到的记录下_MySQL

mysql 复杂的查询语句,工作中用到的记录下_MySQL

WBOY
WBOYOriginal
2016-06-01 13:09:441008Durchsuche

1  去重查询

select distinct id from user_info where xxxxxx

2 group by 分组查询中排序

group by本身没有排序功能,这可能是mysql不完美的地方,但是我们可以这样做

select attack_id, time from (select * from attack_log where (time+172800)

*注:先通过排序行成一个集合,然后再去改集合中去查,这样分组就实现了排序查询

3 查找符合要求的 前两个数据

 select attack_id,time from attack_log a where (select count(*) from attack_log where attack_id = a.attack_id and time > a.time) 

*注:where 后面 其实是一个bool值。通过bool值来过滤 符合要求的数据

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:MySQL管理与优化(4)_MySQLNächster Artikel:centos 下安装 mysql 5.6_MySQL