数据库语言 数据查询_使用这种简单的查询语言开始查询数据

数据库语言 数据查询

Working with data is becoming an increasingly important skill in the modern workplace.

在现代工作场所中,处理数据已成为越来越重要的技能。

Data is no longer the domain of analysts and software engineers. With today's technology, anyone can work with data to analyse trends and inform their decision making.

数据不再是分析师和软件工程师的领域。 借助当今的技术,任何人都可以使用数据来分析趋势并为决策提供依据。

A fundamental concept when working with data is 'querying' a data set. This is to literally ask questions about a set of data. A query language is a software language that provides a syntax for asking such questions.

处理数据时的基本概念是“查询”数据集。 这是从字面上询问有关一组数据的问题。 查询语言是一种软件语言,提供用于询问此类问题的语法。

If you don't have any experience writing queries, they can appear a little intimidating. However, with a little practice, you can master the basics.

如果您没有编写查询的经验,它们可能会显得有些吓人。 但是,只需进行一些练习,即可掌握基础知识。

Here's how you can get started in Google Sheets.

这是您开始使用Google表格的方法 。

Google可视化API查询语言 (Google Visualization API Query Language)

You may already be using Google Sheets for much of your day-to-day work. Perhaps you are familiar with using it to generate charts and graphs.

您可能已经在大部分日常工作中使用Google表格。 也许您熟悉使用它来生成图表。

The Google Visualization API Query Language is the magic that works behind the scenes to make this possible.

Google Visualization API查询语言是在幕后起作用的魔力,使之成为可能。

But did you know you can access this language through the QUERY() function? It can be a powerful tool for working with large sheets of data.

但是您知道可以通过QUERY()函数访问此语言吗? 它是处理大量数据的强大工具。

There are a lot of similarities between the query language and SQL.

查询语言和SQL之间有很多相似之处。

In both cases, you define a data set of columns and rows, and choose different columns and rows by specifying various criteria and conditions.

在这两种情况下,您都将定义列和行的数据集,并通过指定各种条件和条件来选择不同的列和行。

In this article, the example data will come from a large CSV file containing international football results between 1872 and 2019. You can download the data from Kaggle.

在本文中,示例数据将来自一个大型CSV文件,其中包含1872年至2019年之间的国际足球比赛结果。您可以从Kaggle下载数据 。

In a new Google Sheet, upload the CSV file. You can select all the data with Ctrl+A (or Cmd+A on Mac).

在新的Google表格中,上传CSV文件。 您可以使用Ctrl + A(在Mac上为Cmd + A)选择所有数据。

From the menu ribbon, choose Data > Named ranges... and call the range selected something like 'data'. This will make it easier to work with.

从功能区菜单中,选择“数据”>“命名范围...”,然后将所选范围称为“数据”。 这将使其更易于使用。

Now, you are ready to start querying the data. Create a new tab in the spreadsheet, and in cell A1, create a new QUERY() formula.

现在,您可以开始查询数据了。 在电子表格中创建一个新选项卡,并在单元格A1中创建一个新的QUERY()公式。

获取所有英格兰比赛 (Get all England matches)

This first query finds all the rows in the data set where England are either the home team or the away team.

第一个查询查找数据集中所有英格兰为主队或客队的行。

The QUERY() formula takes at least two arguments. The first is the named range, which will be the data set queried. The second is a string that contains the actual query.

QUERY()公式至少接受两个参数。 第一个是命名范围,它将是查询的数据集。 第二个是包含实际查询的字符串。

=QUERY(data, "SELECT * WHERE B = 'England' OR C = 'England'")

Let's break this down.

让我们分解一下。

SELECT * asks to return all columns in the data set. If you only wanted columns A, B and C, you would write SELECT A, B, C.

SELECT *要求返回数据集中的所有列。 如果只需要A,B和C列,则可以编写SELECT A, B, C

Next, you include a filter to find only rows where column B or column C contain the team 'England'. Make sure to use single-quotes for strings inside the query. Double-quotes are used to open and close the query itself.

接下来,包括一个过滤器,以仅查找B列或C列包含团队'England' 。 确保查询中的字符串使用单引号。 双引号用于打开和关闭查询本身。

This formula returns all the rows where England have played. If you want to search for another team, simply change the condition in the filter.

此公式将返回英格兰已打过的所有行。 如果要搜索另一个团队,只需在过滤器中更改条件。

计算所有友谊赛 (Count all friendly matches)

Next, let's count how many friendly matches are in the data set.

接下来,让我们计算一下数据集中有多少个友好匹配项。

=QUERY(data, "SELECT COUNT(A) WHERE F = 'Friendly'")

This makes use of the Query Language's COUNT() function. This is an example of an aggregate function. Aggregate functions summarise many rows into one.

这利用了查询语言的COUNT()函数。 这是聚合函数的示例。 聚合函数将许多行汇总为一。

For example, in this data set there are 16,716 rows where column F equals 'Friendly'. Instead of returning all these rows, the query returns a single row - which counts them instead.

例如,在此数据集中,有16,716行,其中列F等于'Friendly' 。 查询不返回所有这些行,而是返回单个行-对其进行计数。

Other examples of aggregate functions include MAX(), MIN() and AVG(). Instead of returning all the rows matching the query, it finds their maximum, minimum and average values instead.

聚合函数的其他示例包括MAX()MIN()AVG() 。 而不是返回与查询匹配的所有行,而是查找它们的最大值,最小值和平均值。

按比赛分组 (Group by tournament)

Aggregate functions can do more if you use a GROUP BY statement alongside them. This query finds out how many matches have been played by each tournament type.

如果在汇总函数旁边使用GROUP BY语句,则汇总函数可以做更多事情。 该查询找出每种锦标赛类型进行了多少场比赛。

=QUERY(data, "SELECT F, COUNT(A) GROUP BY F")

This query groups the data set by each of the values in column F. It then counts how many rows there are in each group.

该查询按F列中的每个值对数据集进行分组。然后它计算每个组中有多少行。

You can use GROUP BY on more than one column. For example, to find how many matches have been played in each country by tournament, use the query below:

您可以在多个列上使用GROUP BY 。 例如,要查找每个国家在锦标赛中进行了多少场比赛,请使用以下查询:

=QUERY(data, "SELECT H, F, COUNT(A) GROUP BY H, F")

Let's try some more advanced filtering.

让我们尝试一些更高级的过滤。

获取所有英格兰vs德国的比赛 (Get all England vs Germany matches)

You can specify more complex filter logic using the AND and OR keywords. For readability, it can help to use brackets around each part of the filter.

您可以使用ANDOR关键字指定更复杂的过滤器逻辑。 为了便于阅读,可以在过滤器的每个部分周围使用方括号。

For example, to find all the matches between England and Germany:

例如,要查找英格兰和德国之间的所有比赛:

=QUERY(data, "SELECT * WHERE (B = 'England' AND C = 'Germany') OR (C = 'England' AND B ='Germany')")

This filter has two criteria - one where England are the home team and Germany are away, and the other vice versa.

此筛选条件有两个条件-一个条件是英格兰是主队,而德国则不在,另一个则相反。

Using data validation makes it easy to pick any two teams in the data set.

使用数据验证可轻松选择数据集中的任何两个团队。

Then, you can write a query that uses the values of different cells in its filter. Remember to use single-quotes for identifying strings within the query, and double-quotes to open and close different pieces of the query.

然后,您可以编写一个查询,该查询使用其过滤器中不同单元格的值。 请记住使用单引号标识查询中的字符串,并使用双引号打开和关闭查询的不同部分。

=QUERY(data, "SELECT * WHERE (B = '"&B1&"' AND C = '"&B2&"') OR (C = '"&B1&"' AND B ='"&B2&"')")

Aggregate functions and filters make powerful tools when used in combination. Once you are comfortable with how they work, you can start searching for all kinds of interesting trends in your data set.

聚合函数和过滤器结合使用时将成为强大的工具。 一旦熟悉了它们的工作方式,就可以开始在数据集中搜索各种有趣的趋势。

For example, the query below finds the average goals per game, by each year since 1900.

例如,下面的查询查找自1900年以来每年的每场比赛平均目标。

=QUERY(data, "SELECT YEAR(A), AVG(D) + AVG(E) WHERE YEAR(A) >= 1900 GROUP BY YEAR(A)")

If you plot the query result as a line graph, you can immediately start seeing trends over time.

如果将查询结果绘制为折线图,则可以立即开始查看一段时间内的趋势。

排序结果 (Ordering the results)

Sometimes, you are not interested in finding all the matching rows in a data set. Often, you will want to sort them according to some criteria. Perhaps you only wish to find the top ten records.

有时,您对查找数据集中的所有匹配行都不感兴趣。 通常,您将需要根据一些条件对它们进行排序。 也许您只希望找到前十个记录。

This query finds the top ten highest scoring matches in the data set.

此查询查找数据集中得分最高的十个匹配项。

=QUERY(data, "SELECT * ORDER BY (D+E) DESC LIMIT 10")

Notice the ORDER BY statement. This sorts the rows according to the columns specified.  Here, the query sorts the output by the number of goals scored in the game.

注意ORDER BY语句。 这将根据指定的列对行进行排序。 在此,查询按游戏中得分的目标数对输出进行排序。

The DESC keyword indicates to sort in descending order (the ASC keyword would have sorted them in ascending order).

DESC关键字指示按降序排序( ASC关键字将按升序对它们排序)。

Finally, the LIMIT keyword restricts the output to a given number of rows (in this case, ten).

最后, LIMIT关键字将输出限制为给定的行数(在本例中为10行)。

Looks like there have been some pretty one-sided games in Oceania!

好像在大洋洲有一些漂亮的单面游戏!

哪些城市举办了最多的世界杯比赛? (Which cities have hosted the most World Cup matches?)

And now for one final example to bring everything together and get your imagination going.

现在,作为最后一个例子,将所有内容整合在一起,激发您的想象力。

This query finds the top ten cities that have hosted the most FIFA World Cup matches.

此查询查找举办最多FIFA世界杯比赛的前十名城市。

=QUERY(data, "SELECT G, COUNT(A) WHERE F = 'FIFA World Cup' GROUP BY G ORDER BY COUNT(A) DESC LIMIT 10")

现在轮到你了 (Now it's your turn)

Hopefully you have found this article useful. If you are comfortable with the logic in each example, then you are ready to try out real SQL.

希望您发现本文有用。 如果您熟悉每个示例中的逻辑,那么您就可以尝试使用实际SQL。

This will introduce concepts such as JOINS, nested queries and WINDOW functions. When you master these, your power to manipulate data will go through the roof.

这将介绍诸如JOINS,嵌套查询和WINDOW函数之类的概念。 当您掌握了这些内容后,您处理数据的能力就会大打折扣。

There are a number of places to start with learning SQL. Try out the interactive examples at w3schools!

有很多地方可以开始学习SQL。 在w3schools上尝试互动示例 !

翻译自: https://www.freecodecamp.org/news/start-querying-data-with-google-query-language/

数据库语言 数据查询

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391615.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

面向对象编程思想-观察者模式

一、引言 相信猿友都大大小小经历过一些面试,其中有道经典题目,场景是猫咪叫了一声,老鼠跑了,主人被惊醒(设计有扩展性的可加分)。对于初学者来说,可能一脸懵逼,这啥跟啥啊是&#x…

typescript 使用_如何使用TypeScript轻松修改Minecraft

typescript 使用by Josh Wulf通过乔什沃尔夫(Josh Wulf) 如何使用TypeScript轻松修改Minecraft (How to modify Minecraft the easy way with TypeScript) Usually, modifying Minecraft requires coding in Java, and a lot of scaffolding. Now you can write and share Min…

Python:在Pandas数据框中查找缺失值

How to find Missing values in a data frame using Python/Pandas如何使用Python / Pandas查找数据框中的缺失值 介绍: (Introduction:) When you start working on any data science project the data you are provided is never clean. One of the most common …

监督学习-回归分析

一、数学建模概述 监督学习:通过已有的训练样本进行训练得到一个最优模型,再利用这个模型将所有的输入映射为相应的输出。监督学习根据输出数据又分为回归问题(regression)和分类问题(classfication)&#…

leetcode 54. 螺旋矩阵(递归)

给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。 示例 1: 输入:matrix [[1,2,3],[4,5,6],[7,8,9]] 输出:[1,2,3,6,9,8,7,4,5] 示例 2: 输入:matrix [[1,…

微服务架构技能

2019独角兽企业重金招聘Python工程师标准>>> 微服务架构技能 博客分类: 架构 (StuQ 微服务技能图谱) 2课程简介 本课程分为基础篇和高级篇两部分,旨在通过完整的案例,呈现微服务的开发、测试、构建、部署、…

phpstorm 调试_PhpStorm中的多用户调试

phpstorm 调试by Ray Naldo雷纳尔多(Ray Naldo) PhpStorm中的多用户调试 (Multi-User Debugging in PhpStorm) 使用Xdebug和DBGp代理 (Using Xdebug and DBGp Proxy) “Er, wait a minute… Don’t you just use xdebug.remote_connect_back which has been introduced since …

Tableau Desktop认证:为什么要关心以及如何通过

Woah, Tableau!哇,Tableau! By now, almost everyone’s heard of the data visualization software that brought visual analytics to the public. Its intuitive drag and drop interface makes connecting to data, creating graphs, and sharing d…

约束布局constraint-layout导入失败的解决方案 - 转

今天有同事用到了约束布局,但是导入我的工程出现错误 **提示错误: Could not find com.Android.support.constraint:constraint-layout:1.0.0-alpha3** 我网上查了一下资料,都说是因为我的androidStudio版本是最新的稳定版导入这个包就会报这…

算法复习:冒泡排序

思想:对于一个列表,每个数都是一个"气泡 ",数字越大表示"越重 ",最重的气泡移动到列表最后一位,冒泡排序后的结果就是“气泡”按照它们的重量依次移动到列表中它们相应的位置。 算法:搜索整个列表…

leetcode 59. 螺旋矩阵 II(递归)

给你一个正整数 n ,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形矩阵 matrix 。 示例 1: 输入:n 3 输出:[[1,2,3],[8,9,4],[7,6,5]] 解题思路 按层进行数字的填充,每一层…

前端基础进阶(七):函数与函数式编程

纵观JavaScript中所有必须需要掌握的重点知识中,函数是我们在初学的时候最容易忽视的一个知识点。在学习的过程中,可能会有很多人、很多文章告诉你面向对象很重要,原型很重要,可是却很少有人告诉你,面向对象中所有的重…

期权数据 获取_我如何免费获得期权数据

期权数据 获取by Harry Sauers哈里绍尔斯(Harry Sauers) 我如何免费获得期权数据 (How I get options data for free) 网页抓取金融简介 (An introduction to web scraping for finance) Ever wished you could access historical options data, but got blocked by a paywall…

显示与删除使用工具

右击工具菜单栏中的空白处选择自定义 在弹出的自定义菜单中选择命令选项在选择想要往里面添加工具的菜单,之后在选择要添加的工具 若想要删除工具栏中的某个工具,在打开自定义菜单后,按住鼠标左键拖动要删除工具到空白处 例如 转载于:https:/…

js值的拷贝和值的引用_到达P值的底部:直观的解释

js值的拷贝和值的引用介绍 (Introduction) Welcome to this lesson on calculating p-values.欢迎参加有关计算p值的课程。 Before we jump into how to calculate a p-value, it’s important to think about what the p-value is really for.在我们开始计算p值之前&#xff…

leetcode 115. 不同的子序列(dp)

给定一个字符串 s 和一个字符串 t ,计算在 s 的子序列中 t 出现的个数。 字符串的一个 子序列 是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串。(例如,“ACE” 是 “ABCDE…

监督学习-KNN最邻近分类算法

分类(Classification)指的是从数据中选出已经分好类的训练集,在该训练集上运用数据挖掘分类的技术建立分类模型,从而对没有分类的数据进行分类的分析方法。 分类问题的应用场景:用于将事物打上一个标签,通常…

istio 和 kong_如何启动和运行Istio

istio 和 kongby Chris Cooney克里斯库尼(Chris Cooney) 如何启动和运行Istio (How to get Istio up and running) 而一旦完成,您就可以做的疯狂的事情。 (And the crazy stuff you can do once it is.) The moment you get Istio working on your cluster, it fee…

js练习--贪吃蛇(转)

最近一直在看javascript,但是发现不了动力。就开始想找动力,于是在网上找到了一个用js写的贪吃蛇游戏。奈何还不会用git,就只能先这样保存着。哈哈哈,这也算第一篇博客了,以后会坚持用自己的代码写博客的,下…

bzoj千题计划169:bzoj2463: [中山市选2009]谁能赢呢?

http://www.lydsy.com/JudgeOnline/problem.php?id2463 n为偶数时,一定可以被若干个1*2 矩形覆盖 先手每次从矩形的一端走向另一端,后手每次走向一个新的矩形 所以先手必胜 n为奇数时,先手走完一步后,剩下同n为偶数 所以先手必败…