我有三个表:界、站和时间
Bound有2列:boundID和boundName
Station有3列:stationID stationName boundID
时间有4列:时间ID部门时间电车ID车站ID
我正在使用此查询来获取boundName,但似乎无法获取数据。任何帮助都将不胜感激!
$query ="SELECT b.boundName, s.stationName, t.departureTime
from Station s, Time t, Bound b
where s.stationID = t.stationID
AND t.departureTime !=''
AND s.boundID = b.boundID
AND b.boundName";
}
感谢
您必须删除最后一个:"AND b.boundName".
使用此:
$query ="SELECT bound.boundName FROM bound, station, time WHERE
station.stationID = time.stationID AND time.departureTime !='' AND
station.boundID = bound.boundID";
或者这个:
$query ="SELECT b.boundName, s.stationName, t.departureTime
from Station s, Time t, Bound b
where s.stationID = t.stationID
AND t.departureTime !=''
AND s.boundID = b.boundID";
如果您使用join,请尝试此
SELECT
`time`.`departureTime`
, `station`.`stationName`
, `bound`.`boundName`
FROM
`test`.`station`
LEFT JOIN `test`.`bound`
ON (`station`.`boundID` = `bound`.`boundID`)
LEFT JOIN `test`.`time`
ON (`time`.`stationID` = `station`.`stationID`);