您好,在网站上搜索了几个小时之后,我没有找到答案!
| groups.id |名称|日期|日期结束
| 12345678 | abc | 12/12/09 | 12/12/09
| 12345678 | abc | 13/01/23 | 13/01/23
| 23456677 | bdc | 01/01/18 | 01/01/18
我想要这个输出:
| groups.id |名称|日期|日期结束
| 12345678 | abc | 12/12/09 | 12/12/09
| 23456677 | bdc | 01/01/18 | 01/01/18
谢谢!
SELECT DISTINCT (projects_prj.uuid_group_prj),groups.country_alpha2_prj,
groups.title_prj,projects_prj.start_prj,projects_prj.end_prj,crisis.toDate,
crisis.fromDate,crisis.calculationType,crisis.level,crisis.reportlink,
groups.location_prj_lat,groups.location_prj_long,crisis.long_disaster,
crisis.lat_disaster,kml_link,
get_distance_metres(groups.location_prj_lat,groups.location_prj_long,crisis.lat_disaster,crisis.long_disaster)/1000 as km
FROM `projects_prj`, groups,crisis
WHERE groups.uuid_group_prj= projects_prj.uuid_group_prj
and projects_prj.status_prj ='FREE'
and projects_prj.end_prj >= NOW()
and crisis.toDate >= NOW() - INTERVAL 3 DAY
and (groups.location_prj_lat <= crisis.lat_disaster +1 AND groups.location_prj_lat >= crisis.lat_disaster -1) AND (groups.location_prj_long <= crisis.long_disaster +1 AND groups.location_prj_long >= crisis.long_disaster - 1)
答案 0 :(得分:0)
要获取名称的单个实例,可以使用group by
SELECT DISTINCT (projects_prj.uuid_group_prj),groups.country_alpha2_prj,
groups.title_prj,projects_prj.start_prj,projects_prj.end_prj,crisis.toDate,
crisis.fromDate,crisis.calculationType,crisis.level,crisis.reportlink,
groups.location_prj_lat,groups.location_prj_long,crisis.long_disaster,
crisis.lat_disaster,kml_link,
get_distance_metres(groups.location_prj_lat,groups.location_prj_long,crisis.lat_disaster,crisis.long_disaster)/1000 as km
FROM `projects_prj`, groups,crisis
WHERE groups.uuid_group_prj= projects_prj.uuid_group_prj
and projects_prj.status_prj ='FREE'
and projects_prj.end_prj >= NOW()
and crisis.toDate >= NOW() - INTERVAL 3 DAY
and (groups.location_prj_lat <= crisis.lat_disaster +1 AND groups.location_prj_lat >= crisis.lat_disaster -1) AND (groups.location_prj_long <= crisis.long_disaster +1 AND groups.location_prj_long >= crisis.long_disaster - 1)
group by projects_prj.uuid_group_prj,Free2016.projects_prj.start_pr
-- This may be the wrong column, but group it by that 'Name' one you have in your question