日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

程序员 sql面试_非程序员SQL使用指南

發(fā)布時(shí)間:2023/11/29 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 程序员 sql面试_非程序员SQL使用指南 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

程序員 sql面試

Today, the word of the moment is DATA, this little combination of 4 letters is transforming how all companies and their employees work, but most people don’t really know how data behaves or how to access it and they also think that this is just for the tech dude from the IT team or someone who knows to code.

今天,關(guān)鍵是DATA,這四個(gè)字母的小組合正在改變所有公司及其員工的工作方式,但是大多數(shù)人并不真正了解數(shù)據(jù)的行為方式或訪問(wèn)方式,他們還認(rèn)為這僅僅是來(lái)自IT團(tuán)隊(duì)或知道編碼的人的技術(shù)花花公子。

So this article is going to explain a part of this complex world in an easy way and we shall begin by the beginning… the data.

因此,本文將以一種簡(jiǎn)單的方式來(lái)解釋這個(gè)復(fù)雜世界的一部分,我們將從頭開(kāi)始……數(shù)據(jù)。

Basically, we can segment data into two groups, Structured and Unstructured.

基本上,我們可以將數(shù)據(jù)分為兩組,即結(jié)構(gòu)化非結(jié)構(gòu)化

Source: https://lawtomated.com/structured-data-vs-unstructured-data-what-are-they-and-why-care/資料來(lái)源: https : //lawtomated.com/structured-data-vs-unstructured-data-what-are-they-and-why-care/

As you can see, Unstructured data is way more abundant than Structured, but despite that what is more common to use in the usual day-to-day is the Structured one and this occurs for some reasons as:

如您所見(jiàn),非結(jié)構(gòu)化數(shù)據(jù)比結(jié)構(gòu)化數(shù)據(jù)要豐富得多,盡管如此,在日常日常使用中更常見(jiàn)的是結(jié)構(gòu)化數(shù)據(jù),這種情況發(fā)生的原因如下:

  • Can be displayed in rows and columns

    可以顯示在行和列中
  • Requires less storage

    需要更少的存儲(chǔ)空間
  • Easier to manage and manipulate

    易于管理和操縱

I’m not here to say that this 80% is not important, quite the opposite, but it’s just a bit more complex to deal with it so it’s no the focus of this text.

我并不是要說(shuō)這80%并不重要,恰恰相反,但是處理起來(lái)稍微復(fù)雜一點(diǎn),所以它不是本文的重點(diǎn)。

Having this explained, we know that our objective is to learn a little bit of how can we access and manipulate this kind of data.

對(duì)此進(jìn)行了解釋后,我們知道我們的目標(biāo)是學(xué)習(xí)一些有關(guān)如何訪問(wèn)和操作此類(lèi)數(shù)據(jù)的知識(shí)。

結(jié)構(gòu)化數(shù)據(jù)概念 (Structured Data Concepts)

Let’s use this image below as an example:

讓我們以下面的圖片為例:

Source: https://neo4j.com/blog/rdbms-graphs-why-relational-databases-arent-enough/資料來(lái)源: https : //neo4j.com/blog/rdbms-graphs-why-relational-databases-arent-enough/

Structured data is organized in Tables, in this image, we have three and they are Persons, Dept_Members, and Department.

結(jié)構(gòu)化數(shù)據(jù)按表格組織,在此圖像中,我們有三個(gè),分別是Persons,Dept_Members和Department。

Each Table is organized in Columns and Rows.

每個(gè)表都按組織

Each column has a data type, depending on the database that you are using the name or the number of available data types can change, but basically we have in a macro vision Strings, Numbers, Dates, and Timestamps.

每列都有一種數(shù)據(jù)類(lèi)型 ,具體取決于您使用的數(shù)據(jù)庫(kù)的名稱(chēng)或可用數(shù)據(jù)類(lèi)型的數(shù)量可以更改,但是從本質(zhì)上講 ,我們?cè)诤攴矫婢哂?strong>Strings , NumbersDatesTimestamps

  • Strings: Everything that is a text.

    字符串:一切都是文本。
  • Numbers: Everything that is, obviously, a number.

    數(shù)字:顯然所有的東西都是數(shù)字。
  • Dates: Only dates are accepted, it doesn’t count with hours, minutes, and seconds.

    日期:僅接受日期,不計(jì)小時(shí),分鐘和秒。
  • Timestamps: Dates with hours, minutes, and seconds.

    時(shí)間戳記:帶有小時(shí),分鐘和秒的日期。

As I said, some databases change some names or have some more specific uses, for example:

正如我所說(shuō),某些數(shù)據(jù)庫(kù)會(huì)更改某些名稱(chēng)或具有某些更特定的用途,例如:

In Oracle when we want to declare a string column we can call it by VARCHAR2 or CHAR, the difference between them is the number of characters that they deal with (char stores only one character while varchar2 stores N) and if we look to Google Big Query we just have the String data type for all cases of text data.

在Oracle中,當(dāng)我們想聲明一個(gè)字符串列時(shí),可以通過(guò)VARCHAR2或CHAR來(lái)調(diào)用它,它們之間的區(qū)別是它們處理的字符數(shù)(char僅存儲(chǔ)一個(gè)字符,而varchar2存儲(chǔ)N),并且如果我們查看Google Big查詢我們僅具有用于文本數(shù)據(jù)所有情況的String數(shù)據(jù)類(lèi)型。

Well, once we have spoken about the columns now what left is to talk about the rows. Basically, each row is a record of the Table and the one very important question is “How can we differentiate one record from another? What does separate them?”

好了,一旦我們談?wù)摿肆?#xff0c;剩下的就是談?wù)撔小?基本上,每一行都是表的記錄,一個(gè)非常重要的問(wèn)題是“如何區(qū)分一條記錄與另一條記錄? 它們之間有什么區(qū)別?”

The answer is the Primary Key.

答案是主鍵

The combination of columns of a record in a table that makes it unique is the primary key. Some tables have a specific column that works as an index, this works as a primary key too, but it does not show to you what makes it unique.

使記錄唯一的表中各列的組合是主鍵。 有些表有一個(gè)特定的列用作索引,該列也用作主鍵,但是并沒(méi)有向您顯示使其獨(dú)特的原因。

Index/Id example, Source: http://gavo.mpa-garching.mpg.de/Millennium/Help/databaseconcepts索引/ ID示例,來(lái)源: http : //gavo.mpa-garching.mpg.de/Millennium/Help/databaseconcepts Source: https://docs.microsoft.com/pt-br/sql/relational-databases/tables/primary-and-foreign-key-constraints?view=sql-server-ver15來(lái)源: https : //docs.microsoft.com/pt-br/sql/relational-databases/tables/primary-and-foreign-key-constraints?view=sql-server-ver15

Some databases describe it in the table documentation, but if you don’t have this information don’t be afraid and explore your dataset!

一些數(shù)據(jù)庫(kù)在表文檔中對(duì)此進(jìn)行了描述,但是,如果您沒(méi)有此信息,請(qǐng)不要害怕并探索您的數(shù)據(jù)集!

And here comes the main goal of the article: How do I explore it?

這是本文的主要目標(biāo): 如何探索它?

結(jié)構(gòu)化查詢語(yǔ)言(SQL) (Structured Query Language (SQL))

Structured Query Language is the standard declarative search language for relational database

結(jié)構(gòu)化查詢語(yǔ)言是關(guān)系數(shù)據(jù)庫(kù)的標(biāo)準(zhǔn)聲明式搜索語(yǔ)言

This text above it the dictionary explanation of what is SQL, but we can translate it by the code language that lets us get data from one table or a combination of them and how their data is related.

上面的文本對(duì)什么是SQL進(jìn)行了字典解釋,但是我們可以通過(guò)使您可以從一個(gè)表或它們的組合中獲取數(shù)據(jù)以及它們的數(shù)據(jù)如何相關(guān)的代碼語(yǔ)言來(lái)翻譯它。

Resuming it at max we can say that the standard SQL query has “only”, with huge quotes here, 3 elements:

以最大的速度恢復(fù)它,我們可以說(shuō)標(biāo)準(zhǔn)SQL查詢具有“ only”(在此處帶有引號(hào))三個(gè)元素:

  • SELECT: where you define what you want to pick from your tables.

    SELECT :您在其中定義要從表中選擇的內(nèi)容。

  • FROM: where you define which tables you are going to use and their relationship.

    FROM :您將在其中定義要使用的表及其關(guān)系。

  • WHERE: where you define what you want and do not want to see.

    在哪里 :您可以在其中定義想要和不想看到的內(nèi)容。

This is how a query looks like.

這就是查詢的樣子。

Source: the writer資料來(lái)源:作家

Now, what we can understand here:

現(xiàn)在,我們?cè)谶@里可以理解的是:

We want to get data from columns A, B, C, and D from TABLE_1 that is in the SCHEMA_1 (that is like a folder of tables) and we desire just rows with code ‘0001’ in column A.

我們想從SCHEMA_1中的TABLE_1的A,B,C和D列獲取數(shù)據(jù)(就像表的文件夾),并且我們只希望A列中的代碼為“ 0001”的行。

It was easy, isn’t it? Let’s get a little bit more complex example.

很簡(jiǎn)單,不是嗎? 讓我們來(lái)看一些更復(fù)雜的例子。

In column C we have a number (it could be sales quantity, stock projection, purchase order quantity, etc) and we want to sum the values by column A (again, it could be a store or product codes) and column B (maybe a date).

在C列中,我們有一個(gè)數(shù)字(可能是銷(xiāo)售數(shù)量,庫(kù)存預(yù)測(cè),采購(gòu)訂單數(shù)量等),我們想按A列(同樣可以是商店或產(chǎn)品代碼)和B列(可能是一個(gè)約會(huì))。

We also want to order it first by column A and after column B.

我們還希望先按A列然后按B列對(duì)其進(jìn)行排序。

Source: the writer資料來(lái)源:作家

Now, when we want to aggregate some value based on another attribute we have to say “Look, I’m aggregating this guy here ( C ) this way (sum) and by these two dudes (group by A and B).”

現(xiàn)在,當(dāng)我們要基于另一個(gè)屬性匯總一些值時(shí),我們必須說(shuō)“看,我正在以這種方式(和)并通過(guò)這兩個(gè)花花公子(按A和B分組)來(lái)匯總此人(C)。”

By the end, this isn’t too different from the last one, right?

最后,這與上一個(gè)沒(méi)有太大不同,對(duì)嗎?

表之間的關(guān)系 (Relationship Between Tables)

So, until now, all examples were for querying data of only one table at a time, but what we have to do if we want to merge data from two or more different tables?

因此,到目前為止,所有示例都僅一次查詢一個(gè)表的數(shù)據(jù),但是如果要合并來(lái)自兩個(gè)或多個(gè)不同表的數(shù)據(jù)該怎么辦?

The answer is simples, we must say how they relate to each other by simply specifying which columns have equivalent data.

答案很簡(jiǎn)單,我們必須通過(guò)簡(jiǎn)單地指定哪些列具有等效數(shù)據(jù)來(lái)說(shuō)明它們之間的關(guān)系。

Now our example is a sales table, and there I only have center and product codes, and product stock quantity, but I want to get product and center names too but both informations are from other tables.

現(xiàn)在我們的示例是一個(gè)銷(xiāo)售表,那里只有中心代碼和產(chǎn)品代碼以及產(chǎn)品庫(kù)存數(shù)量,但是我也想獲得產(chǎn)品和中心名稱(chēng),但這兩個(gè)信息都來(lái)自其他表。

I’ll say too that I just want to see the stock quantity that is higher than 100 units.

我也要說(shuō)的是,我只想查看高于100個(gè)單位的庫(kù)存數(shù)量。

Let’s focus on the differences between the last example and this one. What is new here?

讓我們集中討論最后一個(gè)示例和這個(gè)示例之間的區(qū)別。 這里有什么新東西?

Tables can have nicknames, this is commonly used when the query has more than one table on it.

表格可以有昵稱(chēng) ,當(dāng)查詢上有多個(gè)表格時(shí),通常使用該昵稱(chēng)

Using this you don’t have to write the whole table location which time you reference it.

使用此方法,您不必在引用該表時(shí)就編寫(xiě)整個(gè)表的位置。

It’s also important because when we join tables we can have the same column names in both tables and we must pass in the query if we are using PLNT_CD from DIM_PLNT or from FT_SLS, otherwise, the query doesn’t know from which table it has to considerate.

這一點(diǎn)也很重要,因?yàn)楫?dāng)我們聯(lián)接表時(shí),兩個(gè)表中的列名可以相同,并且如果我們使用的是DIM_PLNT或FT_SLS的PLNT_CD,則必須傳遞查詢,否則,查詢將不知道從哪個(gè)表周到。

Join is the way you combine data from tables. Always think in two tables at a time, one is called Left and another is the Right.

連接是合并表中數(shù)據(jù)的方式。 總是一次在兩個(gè)表中思考,一個(gè)稱(chēng)為左,另一個(gè)稱(chēng)為右。

Left has a conjunct of records called L, Right has another conjunct called R and some records exist in both.

左有一個(gè)稱(chēng)為L(zhǎng)的記錄的連接,右有另一個(gè)稱(chēng)為R的連接,并且兩者中都存在一些記錄。

Joins can be of several types, the one that is shown in the example is the Left Join, this means that we are going to use only the records of the left table and bring values of Right that has a corresponding value in Left.

聯(lián)接可以有幾種類(lèi)型,示例中顯示的聯(lián)接是“左聯(lián)接”,這意味著我們將僅使用左表的記錄,并在“左”中帶入具有相應(yīng)值的“右”值。

When we are comparing columns from tables to create the join between them we have to remember that is necessary for the relationship to be sealed they must be of the same data type.

當(dāng)我們比較表中的列以創(chuàng)建它們之間的聯(lián)接時(shí),我們必須記住,密封關(guān)系是必要的,它們必須具有相同的數(shù)據(jù)類(lèi)型

In this example, we can see that in the join we had to convert the PLNT_CD field of SLS table to STRING, otherwise the join was not able to be consolidated.

在此示例中,我們可以看到在連接中我們必須將SLS表的PLNT_CD字段轉(zhuǎn)換為STRING,否則無(wú)法合并該連接。

Inside the Where clause, we have a new struct called Between, it is used to filter a range of data. By syntax, it has to be higher than the first parameter and lower than the second one.

在Where子句中,我們有一個(gè)稱(chēng)為Between的新結(jié)構(gòu),用于過(guò)濾一系列數(shù)據(jù)。 通過(guò)語(yǔ)法,它必須高于第一個(gè)參數(shù),并且小于第二個(gè)參數(shù)。

By last, when we have a SUM() or a MEAN() or any other math applied in the query we maybe desire to filter some more specific results and the Having helps us to achieve it by letting us filter the final result of the query before it is shown.

最后,當(dāng)我們?cè)诓樵冎袘?yīng)用了SUM()或MEAN()或任何其他數(shù)學(xué)運(yùn)算時(shí),我們可能希望過(guò)濾一些更具體的結(jié)果,而Haveing通過(guò)讓我們過(guò)濾查詢的最終結(jié)果來(lái)幫助我們實(shí)現(xiàn)此目標(biāo)在顯示之前。

We are getting closer to the end of this article, but before we finish it…

我們接近本文的結(jié)尾,但是在完成本文之前……

提示 (Tips)

  • In case you don’t know what you want to see in the table you can just use a * to return all columns of the table in the query.

    如果您不知道要在表中看到什么,則可以使用*返回查詢中表的所有列。
SELECT
TABLE.*
FROM
SCHEMA.TABLE
  • Basically we have two types of tables, dimensional (DIM) and fact (FT).

    基本上,我們有兩種類(lèi)型的表,維度(DIM)和事實(shí)(FT)。

Dimensional tables store data that is attributed to a store or a product like its name, address, shape, size, etc, think about the data up to date or you maybe say it’s today’s value.

維度表存儲(chǔ)歸因于商店或產(chǎn)品的數(shù)據(jù),例如其名稱(chēng),地址,形狀,大小等,考慮一下最新的數(shù)據(jù),或者您可以說(shuō)它是當(dāng)今的價(jià)值。

Fact tables store data related to transactional information as purchase orders or sales tickets, so it brings the data of the moment of an event.

事實(shí)表將與交易信息相關(guān)的數(shù)據(jù)存儲(chǔ)為采購(gòu)訂單或銷(xiāo)售單,因此它會(huì)帶來(lái)事件發(fā)生時(shí)的數(shù)據(jù)。

  • Types of joins

    聯(lián)接類(lèi)型

There are several types of joins, I could basically write another article just with this theme, but I found this resume that explains a little bit of them.

聯(lián)接有幾種類(lèi)型,我基本上可以只用該主題寫(xiě)另一篇文章,但是我發(fā)現(xiàn)這份簡(jiǎn)歷可以解釋其中的一些內(nèi)容。

Source: https://stackoverflow.com/questions/36882478/how-to-do-sql-joins-in-lambda/36883214資料來(lái)源: https : //stackoverflow.com/questions/36882478/how-to-do-sql-joins-in-lambda/36883214
  • In and not in

    在而不在

Sometimes the need is to get data not of a single product or location, but of a list of them.

有時(shí),需要獲取的數(shù)據(jù)不是單個(gè)產(chǎn)品或位置的數(shù)據(jù),而是列表中的數(shù)據(jù)。

In these cases, you could use the operator IN or NOT IN in the WHERE to set as a parameter a list of desired variables instead of an infinity repetition of ANDs and ORs searching by one parameter at a time.

在這些情況下,可以在WHERE中使用運(yùn)算符IN或NOT IN將所需變量列表設(shè)置為參數(shù),而不是一次按一個(gè)參數(shù)搜索的AND和OR的無(wú)窮重復(fù)。

就是這樣! (And this is it!)

Well, with this I think you can now use SQL to access your data with a little more ease!

好吧,我想您現(xiàn)在可以使用SQL來(lái)更輕松地訪問(wèn)數(shù)據(jù)!

I hope this article has helped you!

希望本文對(duì)您有所幫助!

翻譯自: https://medium.com/swlh/sql-use-guide-for-non-programmers-5997af000c5f

程序員 sql面試

總結(jié)

以上是生活随笔為你收集整理的程序员 sql面试_非程序员SQL使用指南的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。