有没有更好的方法可以将SELECT语句中的ROUND公式用作WHERE子句中的过滤器?
如您在查询中看到的那样,我有以下代码:round((st_distance(ST_Point(vefpicklngactual,vefpicklatactual):: geography,ST_Point(pickgridx,pickgridy))/ 1609.344):: numeric,2)语句,然后在WHERE子句中也使用它们,我尝试将其用作别名,然后在WHERE语句中调用该别名,但没有用。
SELECT vefid, veftripid,
concat(vefpicklatactual, ' ', vefpicklngactual) AS vef_pick,
concat(pickgridy, ' ', pickgridx) AS mta_pick,
round((st_distance(ST_Point(vefpicklngactual,vefpicklatactual)::geography,ST_Point(pickgridx,pickgridy))/1609.344)::numeric,2) AS pick_calc,
concat(vefdroplatactual, ' ', vefdroplngactual) AS vef_drop,
concat(dropgridy, ' ', dropgridx) AS mta_drop,
round((st_distance(ST_Point(vefdroplngactual,vefdroplatactual)::geography,ST_Point(dropgridx,dropgridy))/1609.344)::numeric,2) AS drop_calc
FROM feb_2019_recon
WHERE round((st_distance(ST_Point(vefpicklngactual,vefpicklatactual)::geography,ST_Point(pickgridx,pickgridy))/1609.344)::numeric,2) > 0.5
OR round((st_distance(ST_Point(vefdroplngactual,vefdroplatactual)::geography,ST_Point(dropgridx,dropgridy))/1609.344)::numeric,2) > 0.5;
该查询已经可以正常工作了。我只需要一些技巧,可以在其中优化查询以使其更简洁并减少冗余。