1

我有一个关于列出表格的问题,但我不明白我的错误。它说要列出与计划于 19951 年进行的面试相关的雇主的公司名称、部门、城市。

我正在尝试根据在采访表中找到的 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 秒)

雇主表:

|   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

你有两个问题:

你的表被命名为雇主,你不能从面试中访问 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%';

编辑:

没有雇主的身份证,为了得到你必须做的城市:

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

这行得通,但你真的应该在雇主表上有一个 id,而不是在面试表上重复雇主数据。

您应该在面试表中有一个雇主 ID 外键,如果您需要来自雇主表的信息,您可以通过此 ID 获取它。

于 2013-08-06T23:50:11.253 回答