숙제를 위해 전 세계에 대한 정보 데이터베이스에서 쿼리를 작성해야합니다. 내 쿼리 중 하나에서 오류가 발생하고 이유를 파악할 수 없습니다. 나는에 문제가하고있는 쿼리에 대한 문제 문은 다음과 같습니다PHP의 두 테이블에서 정보를 가져올 때 쿼리 오류가 발생했습니다
는Find all official languages, the country for which it is spoken, and the percentage of speakers
(percentage of speakers is calculated as percentage spoken times country population divided by 100).
Order results by the total number of speakers with the most popular language first. (238 results)
나는 웹 사이트에서 내 쿼리를 실행하려고 할 때 내가 오류는 다음과 같습니다
Query failed: ERROR: missing FROM-clause entry for table "city" LINE 1: ...kers FROM lab2.country AS
co JOIN lab2.country ON lab2.city....^
내가 쓴 코드 내 검색어 :
case 11:
$q = "SELECT name, language, ((pecentage * population)/100) AS
percentage_of_speakers FROM lab2.country AS co JOIN lab2.country ON lab2.city.country_code WHERE
(is_official IS TRUE) ORDER BY percentage_of_speakers DESC";
$result = pg_query($q) or die ('Query failed: '. pg_last_error());
break;
이 쿼리에 대한 정보는 하나가 아닌 두 개의 다른 테이블에서 가져옵니다. 두 테이블에서 데이터를 가져 오려면 JOIN 문을 사용해야한다고 생각합니다. 다음은 사용중인 2 개의 테이블입니다. 사전에 도움을 주셔서 감사합니다.
Table "lab2.country_language"
Column | Type | Modifiers
--------------+-----------------------+----------------------------------------
country_code | character(3) | not null default ''::bpchar
language | character varying(30) | not null default ''::character varying
is_official | boolean | not null default false
percentage | real | not null default 0::real
Table "lab2.country"
Column | Type | Modifiers
-----------------+-----------------------+--------------------------------------
country_code | character(3) | not null default ''::bpchar
name | character varying(52) | not null default ''::character varying
continent | continent | not null
region | character varying(26) | not null default ''::character varying
surface_area | real | not null default 0::real
indep_year | smallint |
population | integer | not null default 0
문제를 올바르게 시도해 주셔서 감사합니다. (같은 코스에있는 다른 학생이 일찍이 이렇게 가난한 시도를 게시했습니다 (http://stackoverflow.com/q/25913964/398670)).앞으로는 숙제에 도움을 청할 때 숙제라고 말하십시오. –