我有三个表:绑定,站点和时间
Bound有2列:boundID和boundName
Station有3列:stationID stationName boundID
时间有4列:timeID departureTime tramID stationID
我使用此查询来获取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";
}
由于
答案 0 :(得分:1)
你必须删除最后一个:'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";
答案 1 :(得分:0)
最后的AND b.boundName不应该存在,因为WHERE条件的计算结果为1或0,因此单个语句也应该相同,这肯定不会返回0或1在你的陈述中。
答案 2 :(得分:0)
如果您使用加入,请尝试
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`);