MySQL also displays records whose count is 0.

Source: Internet
Author: User
Run the following command in MySQL: Select use_city, count (*) from data where OS = "Windows 2003 STD" group by use_city; the result is:
+ ----------- + ---------- +
| Use_city | count (*) |
+ ----------- + ---------- +
| Beijing | 2 |
| Chengdu | 2 |
| Chongqing | 1 |
| Dalian | 2 |
| Fuzhou | 2 |
| Guangzhou | 2 |
| Hangzhou | 2 |
| Nanjing | 2 |
| Shanghai | 21 |
| Shenyang | 5 |
| Wuhan | 1 |
+ ----------- + ---------- +
11 rows in SET (0.01 Sec)

There are a total of 11 records. The problem is that there is no matching record for "Tianjing" in one of the cities. How can I display it
+ ----------- + ---------- +
| Use_city | count (*) |
+ ----------- + ---------- +
| Beijing | 2 |
| Chengdu | 2 |
| Chongqing | 1 |
| Dalian | 2 |
| Fuzhou | 2 |
| Guangzhou | 2 |
| Hangzhou | 2 |
| Nanjing | 2 |
| Shanghai | 21 |
| Tianjing | 0 |
| Shenyang | 5 |
| Wuhan | 1 |
+ ----------- + ---------- +

Show the records whose count is 0 as follows:

Select
Use_city,
Count (case when OS = 'windows 2003 STD 'Then 1 else null end)
From
Data
Group
Use_city

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.