-1
select request_id, request_created_date, request_complaint_type, request_descriptor, 
request_ferry_terminal
from nyc311_requests
    join nyc311_locations_ferries on request_id=request_id
where request_ferry_direction = 'Manhattan Bound' 
order by request_id

我有这段代码,当我尝试执行时,它说每次提到 request_id 时,它都是一个模棱两可的列。

4

2 回答 2

2

您需要查看它来自哪个表,注意我如何将表名添加到 request_id

select nyc311_requests.request_id, request_created_date, request_complaint_type, request_descriptor,
request_ferry_terminal
from nyc311_requests
    join nyc311_locations_ferries on nyc311_requests.request_id=nyc311_locations_ferries.request_id
where request_ferry_direction = 'Manhattan Bound' 
order by request_id 

你也可以给表格别名

select r.request_id, request_created_date, request_complaint_type, request_descriptor,
request_ferry_terminal
from nyc311_requests r
    join nyc311_locations_ferries lf on r.request_id=lf.request_id
where request_ferry_direction = 'Manhattan Bound' 
order by request_id 
于 2013-10-04T16:28:26.287 回答
0

你必须给你的表别名。

select A.request_id, request_created_date, request_complaint_type, request_descriptor, 
request_ferry_terminal
from nyc311_requests A
    join nyc311_locations_ferries B on A.request_id = B.request_id
where request_ferry_direction = 'Manhattan Bound' 
order by request_id

您必须为出现在两个表中的任何字段指定别名,但是一旦您知道如何操作,这将非常简单。

于 2013-10-04T16:28:56.557 回答