Excel is the most commonly used tool in data analysis. This article compares the functions of mysql and excel to introduce how to use mysql to complete data generation, data cleaning, preprocessing, and the most common data classification and data filtering in excel. Classification, aggregation, and data pivot operations. In this article, we introduce parts 5, 6, and 7, data extraction, data screening, and data summary and perspective. This article mainly introduces relevant information on how to use mysql to complete data generation in excel. Friends in need can refer to it.
5. Data extraction
The fifth part is data extraction, which is also the most common task in data analysis. The following describes how to use each function.
Extract data by columns
#Extract data by columns SELECT city FROM data1;
Extract data by rows
#按行提取 SELECT * FROM data1 WHERE city='beijing';
Extract data by location
#按位置提取 SELECT * FROM data1 LIMIT 2,5;
Extract data by conditions
#按条件提取并计算 SELECT AVG(price) FROM data1 WHERE city='beijing' AND age<25;
6, data filtering
The sixth part is data filtering. Use the three conditions of AND, OR, NOT and greater than, less than and equal to filter the data, and perform counting and summing. Similar to the filtering function and countifs and sumifs functions in excel.
Filter by conditions (AND, OR, NOT)
The Excel data directory provides a "Filter" function, which is used to filter data tables according to different conditions. WHERE is used in mysql to complete the filtering operation. With the sum and count functions, it can also realize the functions of sumif and countif functions in excel.
#数据筛选AND SELECT * FROM data1 WHERE city='shanghai' AND age>30;
##
#数据筛选IN SELECT * FROM data1 WHERE city IN ('shanghai','beijing');
#数据筛选OR SELECT * FROM data1 WHERE city='shanghai' OR age>30;
#数据筛选(不等于) SELECT * FROM data1 WHERE city !='beijing';
##
#数据筛选like(模糊筛选) SELECT * FROM data1 WHERE city LIKE 'bei%';
##
#筛选后计数 countif SELECT COUNT(id) AS id_count FROM data1 WHERE city='shanghai'AND age>30;

#筛选后求和 sumtif SELECT SUM(price) AS price FROM data1 WHERE city='beijing' AND age<30;
#筛选后求均值 averageif SELECT AVG(price) AS avg_price FROM data1 WHERE city !='beijing';
##7, Data classification, summary and perspective
Classification and Summary
Excel's data directory provides the "Classification and Summary" function, which can summarize the data table according to the specified fields and summary methods. The corresponding operations are completed through GROUP BY in mysql, and multi-level classification and aggregation can be supported.
GROUP BY is a function for classification and aggregation. The method of use is very simple. Just specify the column name to be grouped. You can also specify multiple column names at the same time. GROUP BY press Column names are grouped in the order in which they appear. At the same time, it is necessary to formulate a summary method after grouping. The two common ones are counting and summing.#单列分类汇总 SELECT city,COUNT(id) AS id_count FROM data1 GROUP BY city ORDER BY id_count;

##
#多列分类汇总 SELECT city,colour,ROUND(SUM(price),2) AS id_count FROM data1 GROUP BY city,colour;
The "PivotTable" function is provided under the insert directory in Excel to summarize the data table according to specific dimensions. Pivot table functionality is not directly provided in mysql. But the same effect is achieved through the CASE WHEN function.
数据透视表也是常用的一种数据分类汇总方式,并且功能上比GROUP BY要强大一些。下面的代码中设定city为行字段,colour为列字段,price为值字段,计算price金额。
#查看原始数据表 SELECT * FROM data1;
#使用CASE WHEN进行数据透视 CREATE VIEW data_Items AS ( SELECT data1.city, CASE WHEN colour = "A" THEN price END AS A, CASE WHEN colour = "B" THEN price END AS B, CASE WHEN colour = "C" THEN price END AS C, CASE WHEN colour = "F" THEN price END AS F FROM data1 );
#查看结果 SELECT * FROM data_Items;
#对字段进行求和汇总 CREATE VIEW data1_Extended_Pivot AS ( SELECT city, SUM(A) AS A, SUM(B) AS B, SUM(C) AS C, SUM(F) AS F FROM data_Items GROUP BY city );
#查看结果 SELECT * FROM data1_Extended_Pivot;
#对空值进行处理 CREATE VIEW data1_Extended_Pivot_Pretty AS ( SELECT city, COALESCE(A, 0) AS A, COALESCE(B, 0) AS B, COALESCE(C, 0) AS C, COALESCE(F, 0) AS F FROM data1_Extended_Pivot );
#查看数据透视结果 SELECT * FROM data1_Extended_Pivot_Pretty;
大家在开发过程中可能会经常遇到,现在就跟着本文尝试操作一下吧。
相关推荐:
The above is the detailed content of How to use mysql to complete data generation in excel. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于折叠表格的相关问题,就是分类汇总的功能,这样查看数据会非常的方便,下面一起来看一下,希望对大家有帮助。

在之前的文章《实用Excel技巧分享:利用 数据透视表 来汇总业绩》中,我们学习了下Excel数据透视表,了解了利用数据透视表来汇总业绩的方法。而今天我们来聊聊怎么计算时间差(年数差、月数差、周数差),希望对大家有所帮助!

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于AGGREGATE函数的相关内容,该函数用法与SUBTOTAL函数类似,但在功能上比SUBTOTAL函数更加强大,下面一起来看一下,希望对大家有帮助。

在之前的文章《实用Word技巧分享:聊聊你没用过的“行号”功能》中,我们了解了Word中你肯定没用过的"行号”功能。今天继续实用Word技巧分享,看看Excel表格怎么借用Word进行分栏打印,快来收藏使用吧!

在之前的文章《实用Excel技巧分享:原来“定位功能”这么有用!》中,我们了解了定位功能的妙用。而今天我们聊聊合并后的单元格如何实现筛选功能,分享一种复制粘贴和方法解决这个问题,另外还会给大家分享一种合并单元格的不错的替代方式。

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于zenmm制作倒计时牌的相关内容,使用Excel中的日期函数结合按指定时间刷新的VBA代码,即可制作出倒计时牌,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于excel的相关知识,其中主要介绍了关于如何使用函数寻找总和为某个值的组合的问题,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Excel的相关知识,其中主要介绍了关于XLOOKUP函数的相关知识,包括了常规查询、逆向查询、返回多列、自动除错以及近似查找等内容,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
