0

我有这个查询

select distinct 
    loc.mID, 
    loc.city, 
    loc.state, 
    loc.zip, 
    loc.country, 
    loc.latitude, 
    loc.longitude, 
    baseInfo.firstname, 
    baseInfo.lastname, 
    baseInfo.profileimg, 
    baseInfo.facebookID, 
    (((acos(sin(('37.8068406'*pi()/180)) * sin((`latitude`*pi()/180))+cos(('37.8068406'*pi()/180)) * cos((`latitude`*pi()/180)) * cos((('-121.3062367' - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance`, teams.teamName, teams.leagueType, teams.teamType, teams.subcat 
FROM memb_geo_locations loc 
left join memb_friends friends on (friends.mID = loc.mID or friends.friendID = loc.mID) and (friends.mID = '100019' or friends.friendID = '100019') 
join memb_baseInfo baseInfo on baseInfo.mID = loc.mID 
join memb_teams teams on teams.mID = loc.mID
where 
    loc.primaryAddress = '1' and ((friends.mID is null or friends.friendID is null) or (friends.isactive = 2)) 
and 
    (teams.teamName like '%Buffalo Bills%' or teams.teamName like '%New England Patriots%' or teams.teamName like '%Dallas Cowboys%')
and 
    loc.mID != 100019 
having 
    `distance` < 50 
order by baseInfo.firstname asc limit 30

这非常适合我的核心需求。但是,我正在尝试弄清楚如何获取查询并对其进行细化,以便

(teams.teamName like '%Buffalo Bills%' or teams.teamName like '%New England Patriots%' or teams.teamName like '%Dallas Cowboys%')

每个团队名称将产生一个最大定义数量的结果(每个都可以减少或没有,只需寻求最大每个),同时具有在查询末尾指定的限制的最大输出。无论如何我可以改进这个查询来做我希望的事情吗?有人在最近的另一篇与此类似的帖子中告诉我,我要检查一下,UNION但我不确定这将如何应用于此查询?假设这是正确的方向。

4

0 回答 0