where子句中的未知列 - 错误的SQL查询?

时间:2013-09-24 19:01:05

标签: sql

查询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   |
---------------        ---------------------         ----------------

2 个答案:

答案 0 :(得分: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'

答案 1 :(得分: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'"