我如何一起加入表1和表2?
表1:
SELECT Roomid, Room, Latitude, Longitude,
ACOS(SIN((:lat))*SIN(RADIANS(Latitude)) + COS((:lat))*COS(RADIANS(Latitude))*COS(RADIANS(Longitude)-(:lon)))*(:R) AS D
FROM Rooms
AS t1
WHERE Latitude>(:minLat) AND Latitude<(:maxLat)
AND Longitude>(:minLon) AND Longitude<(:maxLon)
AND ACOS(SIN((:lat))*SIN(RADIANS(Latitude)) + COS((:lat))*COS(RADIANS(Latitude))*COS(RADIANS(Longitude)-(:lon)))*(:R) < (:rad)
ORDER BY D
limit 6
表2:
SELECT name, date, roomid, descr
FROM Events
AS t2
WHERE date > NOW()
GROUP BY roomid
ORDER BY date
每当我尝试在t1.Roomid = t2.roomid
上执行JOIN时,它都无效。
答案 0 :(得分:1)
试试这个:
SELECT *
FROM
(
SELECT Roomid,
Room,
Latitude,
Longitude,
ACOS(SIN((:lat))*SIN(RADIANS(Latitude)) + COS((:lat))*COS(RADIANS(Latitude))*COS(RADIANS(Longitude)-(:lon)))*(:R) AS D
FROM Rooms
WHERE Latitude>(:minLat) AND
Latitude<(:maxLat) AND
Longitude>(:minLon) AND
Longitude<(:maxLon) AND
ACOS(SIN((:lat))*SIN(RADIANS(Latitude)) + COS((:lat))*COS(RADIANS(Latitude))*COS(RADIANS(Longitude)-(:lon)))*(:R) < (:rad)
) t1
INNER JOIN
(
SELECT `name`, `date`, roomid, `descr`
FROM `Events`
WHERE `date` > NOW()
GROUP BY roomid
) t2
ON t1.RoomID = t2.RoomID
ORDER BY t1.D, t2.`Date`
答案 1 :(得分:0)
SELECT * FROM
(
SELECT Roomid, Room, Latitude, Longitude,
ACOS(SIN((:lat))*SIN(RADIANS(Latitude)) + COS((:lat))*COS(RADIANS(Latitude))*COS(RADIANS(Longitude)-(:lon)))*(:R) AS D
FROM Rooms
AS t1
WHERE Latitude>(:minLat) AND Latitude<(:maxLat)
AND Longitude>(:minLon) AND Longitude<(:maxLon)
AND ACOS(SIN((:lat))*SIN(RADIANS(Latitude)) + COS((:lat))*COS(RADIANS(Latitude))*COS(RADIANS(Longitude)-(:lon)))*(:R) < (:rad)
ORDER BY D
limit 6
) A,
(
SELECT name, date, roomid, descr
FROM Events
AS t2
WHERE date > NOW()
GROUP BY roomid
ORDER BY date
) B
WHERE A.Roomid = B.roomid;
答案 2 :(得分:0)
@Maknelly:为什么这个加入对你不起作用,首先给出你想要加入的自己的代码.......然后我们可以进一步帮助你关注。