我有这样的查询 -
SELECT e.id FROM event e WHERE e.startdatetime<NOW() AND e.isEventDeleted=FALSE AND e.isNeighborlyInvited=TRUE AND e.organized_by!=49 AND e.event_address IN (SELECT id FROM address a WHERE latitude!='' AND longitude!='' AND IFNULL(( 3959 * ACOS( COS( RADIANS(22.6979425) ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(75.8597305) ) + SIN( RADIANS(22.6979425) ) * SIN( RADIANS( latitude ) ))),0)<100) AND e.id NOT IN (SELECT eventid FROM event_interest WHERE approvalStatus!='InterestExpressed' AND interested_user=49) AND e.id NOT IN (SELECT eventid FROM event_invite WHERE invited_user=49 )
UNION
SELECT e.id FROM event e WHERE e.isEventDeleted=FALSE AND e.isNeighborlyInvited=TRUE AND e.organized_by!=49 AND EXISTS (SELECT id FROM address a WHERE latitude!='' AND longitude!='' AND e.event_address=id AND IFNULL(( 3959 * ACOS( COS( RADIANS(22.6979425) ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(75.8597305) ) + SIN( RADIANS(22.6979425) ) * SIN( RADIANS( latitude ) ))),0)<100) AND NOT EXISTS (SELECT eventid FROM event_interest WHERE e.id =eventid AND approvalStatus!='InterestExpressed' AND interested_user=49) AND NOT EXISTS (SELECT eventid FROM event_invite WHERE eventid=e.id AND invited_user=49 )
ORDER BY e.id,((SELECT AVG(avgr.abc) AS VALUE FROM ( SELECT YEAR(NOW())-YEAR(dob) AS abc FROM user_detail WHERE userid=(SELECT interested_user FROM event_interest WHERE eventid=477 AND approvalStatus='Approve') UNION SELECT YEAR(NOW())-YEAR(dob) AS abc FROM user_detail WHERE userid=(SELECT invited_user FROM event_invite WHERE eventid=477 AND acceptance='Accept')) AS avgr)+(SELECT IFNULL(( 3959 * ACOS( COS( RADIANS(22.6979425) ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(75.8597305) ) + SIN( RADIANS(22.6979425) ) * SIN( RADIANS( latitude ) ))),0) FROM address a WHERE latitude!='' AND longitude!='' AND e.event_address=id));
这个在订单条款中给了我错误1054未知列e.id.
我正在检查谷歌的每一个命名错误,但我不知道如何命名错误请告诉我,如果我做错了什么。
答案 0 :(得分:6)
通过从ORDER BY子句中删除e
来尝试此操作,因为您使用的是 UNION 语句:
ORDER BY id
而不是
ORDER BY e.id
答案 1 :(得分:0)
您的原始问题已得到解答。在UNION之后,e.id不再可用。只有id是。
但是我想补充一些内容:
select a, b, c
from
(
select a, b, c, d
... -- complete query here
)
order by d;