數據庫語言 數據查詢_使用這種簡單的查詢語言開始查詢數據

數據庫語言 數據查詢

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.pswp.cn/news/391615.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391615.shtml
英文地址,請注明出處:http://en.pswp.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為偶數 所以先手必敗…