0

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

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

+------------------------------+------------+
| 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)
4

1 回答 1

0

试试这个并检查它是否有效

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

检查以查看您的演示

于 2013-07-21T06:53:40.270 回答