SELECT id, status, category, logourl, businessname, slug
, address2, city, state, country, zipcode, latitude
, longitude, isclaimed
FROM (SELECT distance(33.8730134379712132, -117.5613892553118574, longitude , latitude) AS distance
, id, status, category, logourl, businessname, slug
, address2, city, state, country, zipcode, latitude
, longitude, isclaimed
, rank() over (partition by businessname, city, category order by id desc) as rank
from hmgravy_yelpbusiness ) as dt
where rank = 1 AND slug != ''
AND status = True
AND isclaimed!='Y'
AND (longitude <= 34.01794097420309 AND longitude >= 33.72808590173933
AND ABS(latitude) <= 117.75476524524271 AND ABS(latitude) >= 117.368013265381)
AND distance <= 10
AND category = 'General Contractors'
ORDER BY CASE WHEN LOWER(city) = 'corona' THEN 1 ELSE 2 END
, distance ASC, city ASC, logourl DESC
LIMIT 15 OFFSET 0
;
答案 0 :(得分:0)
select id, class, defaut, input, round(input - defaut) test from table1
group by class, id with rollup
更新:刚刚格式化