当给定的列字符串完全匹配时,如何向新表增加值



mySQL可能很简单,但也可能很复杂,尤其是当它是第一次尝试从逻辑上理解如何执行任务并使表准确可见时。

我家庭作业中的一个问题是:每家公司面试了多少次?先打印出面试次数最多的公司,然后按公司名称按A-Z顺序排序。

+------------------------------+------------+
| companyname                  | Interviews |
+------------------------------+------------+
| Ajax Software, Inc.          |          2 |
| Cameron Industries           |          2 |
| Flordia Software Designs     |          2 |
| Manhattan-Made Software      |          2 |
| Mountainside Magic Software  |          2 |
| Acme Information Source      |          1 |
| ApplDesign                   |          1 |
<<<<<<< cut out some output >>>>>>>>>>>>>>>>>>>
| Vegas Programming and Design |          1 |
| Virginia Software Industries |          1 |
+------------------------------+------------+
23 rows in set (0.00 sec)

我通过编码得到了完美的第一列:

SELECT DISTINCT companyname,
FROM interview
ORDER BY companyname ASC;

但在面试中,我正试图获得代码,如果在公司名称中,有多少公司有相同的确切字符串要增加到面试端。这是怎么回事?

全输出:

+------------------------------+
| companyname                  |
+------------------------------+
| Acme Information Source      |
| Ajax Software, Inc.          |
| Ajax Software, Inc.          |
| ApplDesign                   |
| Bay Software Inc.            |
| Braddock Information Assoc.  |
| Buffalo Software Assoc.      |
| Cameron Industries           |
| Cameron Industries           |
| CCC Software                 |
| Davis-Klein Software         |
| DC Security Applications     |
| Flordia Software Designs     |
| Flordia Software Designs     |
| Focused Applications, Inc.   |
| Georgia Software Design      |
| Jersey Computer Services     |
| Long Island Apps, Inc.       |
| Manhattan-Made Software      |
| Manhattan-Made Software      |
| Mountainside Magic Software  |
| Mountainside Magic Software  |
| Nantucket Applications, Inc. |
| PennState Programming, Inc.  |
| Rochester Software Design    |
| Sandy Hook Software          |
| Vegas Programming and Design |
| Virginia Software Industries |
+------------------------------+
28 rows in set (0.00 sec)

试试这个并检查它是否工作

SELECT companyname ,count(companyname) as interviews
from interview GROUP BY companyname order by interviews desc, companyname asc

查看YOu演示

最新更新