1

查询 MySQL 数据库时收到错误消息:

'where 子句'中的未知列'velvet'

"SELECT ATCOCode,Latitude,Longitude FROM StopCode 
INNER JOIN JourneyStopCode ON StopCode.ATCOCode = JourneyStopCode.StopCode 
INNER JOIN Journey On Journey.Code = JourneyStopCode.JourneyCode 
WHERE JourneyCode = code 
AND Journey.Operator = velvet"

我的 SQL 有什么问题吗?下面是我的表结构。

---------------        ---------------------         ----------------
|  Journey    |        | JourneyStopCode   |         |  StopCode    |
---------------        ---------------------         ----------------
| Code        |        | JourneyStopCodeID |         |  StopCode    |
| Operator    |        | JourneyCode       |         |  Latitude    |
| Description |        | StopCode          |         |  Longitude   |
---------------        ---------------------         ----------------
4

2 回答 2

6

我相信你必须将变量封装成一个字符串。

SELECT ATCOCode,Latitude,Longitude FROM StopCode 
INNER JOIN JourneyStopCode ON StopCode.ATCOCode = JourneyStopCode.StopCode 
INNER JOIN Journey On Journey.Code = JourneyStopCode.JourneyCode 
WHERE JourneyCode = 'code'
AND Journey.Operator = 'velvet'
于 2013-09-24T19:03:32.903 回答
0

尝试这个

"SELECT ATCOCode,Latitude,Longitude FROM StopCode 
INNER JOIN JourneyStopCode ON StopCode.ATCOCode = JourneyStopCode.StopCode 
INNER JOIN Journey On Journey.Code = JourneyStopCode.JourneyCode 
WHERE JourneyCode = code 
AND Journey.Operator = 'velvet'"
于 2013-09-24T19:04:39.930 回答