繁体   English   中英

只选择重复mysql的记录

[英]only select records that repear mysql

我有以下查询

SELECT id
     , created_date 
     , longitude
     , latitude 
  FROM score s
 where s.mobile_user_id = 14299
   and latitude != 0 
   and created_date > '2018-10-01 12:00:00' 
   and speed_range_id > 1
 group  
    by latitude, longitude
 order 
    by id asc;

这将返回以下结果:

  ID        CREATED_DATE           LAT          LON
    8289173 2018-10-02 16:52:54 -100.40871983   20.56314546
    8991287 2018-10-07 18:06:37 -100.40879701   20.56899227
    9077533 2018-10-08 11:55:31 -100.39687493   20.57479211
    9077534 2018-10-08 11:55:31 -100.36075875   20.58076244
    9077535 2018-10-08 11:55:31 -100.37852743   20.60783806
    9077536 2018-10-08 11:55:31 -100.36473954   20.61464554
    9077537 2018-10-08 11:55:31 -100.36424849   20.61501740
    9077538 2018-10-08 11:55:31 -100.40951731   20.60529101
    9227761 2018-10-09 18:10:00 -100.40851908   20.61148848
    9227762 2018-10-09 18:10:00 -100.40545509   20.61769963
    9227763 2018-10-09 18:10:00 -100.38008197   20.61098901
    9227764 2018-10-09 18:10:00 -100.36462022   20.61464574
    9227765 2018-10-09 18:10:00 -100.34415272   20.61327334
    9227766 2018-10-09 18:10:00 -100.33583425   20.61397514

但是,我只想选择多个具有相同created_date的记录,例如本示例中的日期2018-10-08 11:55:31和2018-10-09 18:10:00。 我如何编写查询以忽略不重复的前2个?

我尝试通过使用created_date> 1来尝试,但它似乎不起作用。

有任何想法吗?

由于LAT&LON有所不同,因此无法正常工作,因为您的小组在LAT&LON上。

尝试这个 :

SELECT id, created_date ,longitude,latitude
FROM napify.score s
where s.mobile_user_id = '14299' and latitude != 0.00000000 and created_date > '2018-10-01 12:00:00' and speed_range_id > 1
and created_date in (select created_date from napify.score group by created_date having count(*) > 1)
group by latitude, longitude
order by id asc;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM