1

テーブルの一覧表示について質問がありますが、エラーがわかりません。1995 年に予定されている面接に関連する雇用主の会社名、部門、市区町村をリストするように指示されています1。

インタビュー テーブルで見つかった qtrcode に基づいてレコードを一覧表示しようとしています。

私はこのコードを持っています:

SELECT companyname, division, city
FROM employer
WHERE interview.qtrcode = '%19951%';

ERROR 1054 (42S22): Unknown column 'interview.qtrcode' in 'where clause'

テーブルは次のようになりますが、このエラーにより出力が得られません。

+------------------------------+------------------+------------------+
| companyname                  | division         | city             |
+------------------------------+------------------+------------------+
| Acme Information Source      | Customer Support | Cleveland        |
| Braddock Information Assoc.  | Payroll          | Boston           |
| Ajax Software, Inc.          | Production       | Berkeley         |
| Ajax Software, Inc.          | RandD            | Berkeley         |
| Bay Software Inc.            | Production       | Berkeley         |
| Vegas Programming and Design | Development      | Las Vegas        |
| Mountainside Magic Software  | Management       | Colorado Springs |
| Mountainside Magic Software  | Customer Support | Colorado Springs |
+------------------------------+------------------+------------------+
8 rows in set (0.00 sec)

インタビュー表:

+----+------------+------------------------------+------------------+-------+---------+------+-------+----------+
| ID | Date       | Companyname                  | division         | Qtr.  | $ offer | Hrs. | List? | jobdesc  |
+----+------------+------------------------------+------------------+-------+---------+------+-------+----------+
|  1 | 1995-06-01 | Acme Information Source      | Customer Support | 19951 |   12.00 |   40 | y     | Job Desc |
|  2 | 1995-06-01 | Braddock Information Assoc.  | Payroll          | 19951 |   10.75 |   40 | n     | Job Desc |
|  3 | 1995-06-30 | Ajax Software, Inc.          | Production       | 19951 |   11.00 |   40 | y     | Job Desc |
|  4 | 1995-06-30 | Ajax Software, Inc.          | RandD            | 19951 |   11.50 |   40 | y     | Job Desc |
|  5 | 1995-07-01 | Bay Software Inc.            | Production       | 19951 |   11.75 |   20 | y     | Job Desc |
|  6 | 1995-08-01 | Vegas Programming and Design | Development      | 19951 |   11.00 |   40 | n     | Job Desc |
|  7 | 1995-08-01 | Mountainside Magic Software  | Management       | 19951 |   11.50 |   20 | y     | Job Desc |
|  8 | 1995-08-02 | Mountainside Magic Software  | Customer Support | 19951 |   10.75 |   40 | y     | Job Desc |
|  9 | 1995-12-01 | Cameron Industries           | Management       | 19953 |   13.25 |   35 | n     | Job Desc |
| 10 | 1995-12-02 | Cameron Industries           | Customer Support | 19953 |   13.00 |   35 | n     | Job Desc |
| 11 | 1995-12-04 | CCC Software                 | Production       | 19953 |   11.50 |   40 | n     | Job Desc |
| 12 | 1996-01-21 | DC Security Applications     | RandD            | 19953 |   11.50 |   30 | n     | Job Desc |
| 13 | 1996-02-01 | Davis-Klein Software         | RandD            | 19953 |   11.25 |   20 | n     | Job Desc |
| 14 | 1996-02-02 | Flordia Software Designs     | RandD            | 19953 |   11.75 |   30 | n     | Job Desc |
| 15 | 1996-07-01 | Rochester Software Design    | Development      | 19961 |   12.00 |   30 | n     | Job Desc |
| 16 | 1996-07-01 | Focused Applications, Inc.   | Production       | 19961 |   12.00 |   30 | y     | Job Desc |
| 17 | 1996-08-01 | Georgia Software Design      | RandD            | 19961 |   11.75 |   40 | y     | Job Desc |
| 18 | 1996-08-08 | ApplDesign                   | RandD            | 19961 |   11.50 |   30 | y     | Job Desc |
| 19 | 1996-08-11 | Long Island Apps, Inc.       | Development      | 19961 |   12.25 |   40 | y     | Job Desc |
| 20 | 1997-01-01 | Jersey Computer Services     | Customer Support | 19963 |   12.50 |   35 | n     | Job Desc |
| 21 | 1997-01-01 | Flordia Software Designs     | Development      | 19963 |   12.75 |   30 | n     | Job Desc |
| 22 | 1997-01-31 | Manhattan-Made Software      | Customer Support | 19963 |   12.50 |   40 | y     | Job Desc |
| 23 | 1997-02-01 | Manhattan-Made Software      | Payroll          | 19963 |   13.25 |   40 | y     | Job Desc |
| 24 | 1997-03-24 | Nantucket Applications, Inc. | RandD            | 19964 |   13.00 |   40 | y     | Job Desc |
| 25 | 1997-03-31 | PennState Programming, Inc.  | Management       | 19964 |   13.00 |   40 | y     | Job Desc |
| 26 | 1997-04-20 | Sandy Hook Software          | Development      | 19964 |   12.75 |   35 | n     | Job Desc |
| 27 | 1997-04-22 | Buffalo Software Assoc.      | Payroll          | 19964 |   12.75 |   35 | y     | Job Desc |
| 28 | 1997-05-01 | Virginia Software Industries | Production       | 19964 |   13.75 |   40 | n     | Job Desc |
+----+------------+------------------------------+------------------+-------+---------+------+-------+----------+

セットで 28 行 (0.00 秒)

EMPLOYER テーブル:

|   companyname                    | division         | address                   | city             | statecode | zipcode |
| Acme Information Source        | Customer Support | 132 Commerical Way        | Cleveland        | OH        |   44234 |
| Ajax Software, Inc.            | RandD            | 2421 West Industrial Way  | Berkeley         | CA        |   94710 |
4

1 に答える 1

2

2 つの問題があります。

あなたのテーブルはemployerという名前です。インタビューからqtrcodeにアクセスすることはできません。

面接テーブルに参加するか、雇用主がいるはずの場所で面接を受けるだけの間違いです

この場合、= の代わりに LIKE を使用する必要があります。

SELECT companyname, division, city
FROM employer
WHERE employer.qtrcode LIKE '%19951%';

テーブルインタビューを行うと、次のようになります。

SELECT companyname, division, city
FROM employer, interview
WHERE employer.id = interview.employer_id 
      AND interview.qtrcode LIKE '%19951%';

編集:

あなたがしなければならない都市を取得するために、雇用主にIDを持っていません:

SELECT interview.companyname, interview.division, employer.city
FROM employer, interview
WHERE employer.Companyname = interview.Companyname                   
      AND interview.qtrcode LIKE '%19951%';

これは機能しますが、実際には雇用者テーブルに id を設定し、インタビュー テーブルに雇用者データを複製しないようにする必要があります。

インタビュー テーブルに employee_id 外部キーが必要です。employer テーブルからの情報が必要な場合は、この ID を介して情報を取得します。

于 2013-08-06T23:50:11.253 に答える