数据库逻辑删除的sql语句_通过数据库的眼睛查询sql的逻辑流程
數(shù)據(jù)庫(kù)邏輯刪除的sql語(yǔ)句
Structured Query Language (SQL) is famously known as the romance language of data. Even thinking of extracting the single correct answer from terabytes of relational data seems a little overwhelming. So understanding the logical flow of query is very important.
小號(hào) tructured查詢語(yǔ)言(SQL)是著名的被稱為數(shù)據(jù)的浪漫語(yǔ)言。 甚至想從TB的關(guān)系數(shù)據(jù)中提取單個(gè)正確答案似乎也有些不知所措。 因此,了解查詢的邏輯流程非常重要。
查詢執(zhí)行計(jì)劃 (Query Execution Plan)
SQL is a declarative language, this means SQL query logically describes the question to the SQL Query Optimizer which later decides on the best way to physically execute the query. This method of execution is called the query execution plan. There can be more than one execution plan, so when we say optimize a query that in turn referring to make the query execution plan more efficient.
SQL是一種聲明性語(yǔ)言,這意味著SQL查詢從邏輯上向SQL查詢優(yōu)化器描述了問(wèn)題,SQL優(yōu)化器隨后決定了物理執(zhí)行查詢的最佳方法。 這種執(zhí)行方法稱為查詢執(zhí)行計(jì)劃。 可以有多個(gè)執(zhí)行計(jì)劃,因此當(dāng)我們說(shuō)優(yōu)化查詢時(shí),該查詢反過(guò)來(lái)又使查詢執(zhí)行計(jì)劃更有效。
Let’s look into the 2 flows that a SQL query can be looked through:
讓我們看一下可以查詢SQL查詢的2個(gè)流程:
查詢的句法流程 (Syntactical Flow of Query)
The SELECT statement basically tells the database what data to be retrieved along with which columns, rows, and tables to get the data from, and how to sort the data.
SELECT語(yǔ)句基本上告訴數(shù)據(jù)庫(kù)要檢索哪些數(shù)據(jù)以及從中獲取數(shù)據(jù)的列,行和表,以及如何對(duì)數(shù)據(jù)進(jìn)行排序。
Abbreviated Syntax for the SELECT command [1]SELECT命令的縮寫語(yǔ)法[1]SELECT statement begins with a list of columns or expressions.
SELECT語(yǔ)句以列或表達(dá)式列表開(kāi)頭。
FROM portion of the SELECT statement assembles all the data sources into a result set that is used by the rest of the SELECT statement.
SELECT語(yǔ)句的FROM部分將所有數(shù)據(jù)源組合成一個(gè)結(jié)果集,供其余SELECT語(yǔ)句使用。
WHERE clause acts upon the record set assembled by the FROM clause to filter certain rows based upon conditions.
WHERE子句作用于FROM子句組合的記錄集,以根據(jù)條件過(guò)濾某些行。
GROUP BY clause can group the larger data set into smaller data sets based on the columns specified.
GROUP BY子句可以根據(jù)指定的列將較大的數(shù)據(jù)集分組為較小的數(shù)據(jù)集。
HAVING clause can be used to restrict the result of aggregation by GROUP BY.
HAVING子句可用于限制GROUP BY的聚合結(jié)果。
ORDER BY clause determines the sort order of the result set.
ORDER BY子句確定結(jié)果集的排序順序。
Simplest possible valid SQL statement is :
最簡(jiǎn)單的有效SQL語(yǔ)句是:
SELECT 1; (Oracle a requires FROM DUAL appended to accomplish this)
選擇1; (Oracle要求附加FROM FROM DUAL來(lái)完成此操作)
Hmmm... What is the problem in the flow of “Syntactical Flow”? Can you SELECT data without knowing WHERE it is coming FROM ?? ...Hmmm .. Somewhere there is LOGIC missing right !!! Soo ..
嗯...“句法流”中的問(wèn)題是什么? 您可以在不知道數(shù)據(jù)來(lái)自何處的情況下選擇數(shù)據(jù)嗎? ...嗯..某個(gè)地方缺少LOGIC吧!!! o ..
Smart on Smart在UnsplashUnsplash拍攝查詢的邏輯流程 (Logical Flow of Query)
The best way to think the SQL statement is through the query’s logical flow. Logical may not be the same as physical flow and also it is not the same as the query syntax. Think the query in the following order:
認(rèn)為SQL語(yǔ)句的最佳方法是通過(guò)查詢的邏輯流程。 邏輯可能與物理流程不同,也與查詢語(yǔ)法不同。 按以下順序考慮查詢:
A simplified view of Logical flow [1]邏輯流的簡(jiǎn)化視圖[1]FROM: Logically query starts from the FROM clause by assembling the initial set of data.
FROM :邏輯查詢是通過(guò)組裝初始數(shù)據(jù)集從FROM子句開(kāi)始的。
WHERE: Then where clause is applied to select only the rows that meet the criteria.
WHERE :然后應(yīng)用where子句以僅選擇滿足條件的行。
Aggregations: Later aggregation is performed on the data such as finding the sum, grouping the data values in columns, and filtering the groups.
聚合 :稍后對(duì)數(shù)據(jù)執(zhí)行聚合,例如查找總和,將數(shù)據(jù)值分組到列中以及過(guò)濾組。
Column Expressions: After the above operations the SELECT list is processed along with calculations of any expressions involved in it. (Except column expressions everything else is optional in SQL query.)
列表達(dá)式 :完成上述操作后,將處理SELECT列表以及其中涉及的任何表達(dá)式的計(jì)算。 (除了列表達(dá)式,SQL查詢中的其他所有內(nèi)容都是可選的。)
ORDER BY: After getting the final resulting rows are sorted ascending or descending by ORDER BY clause.
ORDER BY :得到最終的結(jié)果行之后,按ORDER BY子句對(duì)行進(jìn)行升序或降序排序。
OVER: Windowing and ranking functions can later be applied to get a separately ordered view of the result with additional functions for aggregation.
結(jié)束:以后可以使用開(kāi)窗和排名功能來(lái)獲取結(jié)果的單獨(dú)排序視圖,并帶有用于聚合的其他功能。
DISTINCT: This is applied to remove any duplicate rows present in result data.
DISTINCT :用于刪除結(jié)果數(shù)據(jù)中存在的所有重復(fù)行。
TOP: After all this process of selecting data filtering it and performing all the calculations and ordering them, SQL can restrict the result to top few rows.
頂部:在完成所有這些選擇數(shù)據(jù)的過(guò)程之后,對(duì)數(shù)據(jù)進(jìn)行過(guò)濾并執(zhí)行所有計(jì)算并對(duì)它們進(jìn)行排序,SQL可以將結(jié)果限制在前幾行。
INSERT, UPDATE, DELETE: This is the final logical step of the query to perform data modification using the resulting output.
INSERT,UPDATE,DELETE:這是查詢的最后邏輯步驟,用于使用結(jié)果輸出執(zhí)行數(shù)據(jù)修改。
UNION: The output from the multiple queries can be stacked to using the UNION command.
UNION :可以使用UNION命令將多個(gè)查詢的輸出堆疊在一起。
For all the data anlysts who are working on database or datawarehouse projects. It is very important to understand the logical flow and the basic logic behind it. In any data anlysis project, data collection would be first step (FROM) and removing unessecarry data (WHERE) and then ordering the data (ORDER BY) follows.
對(duì)于從事數(shù)據(jù)庫(kù)或數(shù)據(jù)倉(cāng)庫(kù)項(xiàng)目的所有數(shù)據(jù)分析師。 了解邏輯流程及其背后的基本邏輯非常重要。 在任何數(shù)據(jù)分析項(xiàng)目中,數(shù)據(jù)收集都是第一步(FROM),然后刪除未保密的數(shù)據(jù)(WHERE),然后對(duì)數(shù)據(jù)進(jìn)行排序(ORDER BY)。
翻譯自: https://medium.com/@manoj.bidadiraju/logical-flow-of-sql-query-sql-through-the-eye-of-database-e7d111c87516
數(shù)據(jù)庫(kù)邏輯刪除的sql語(yǔ)句
總結(jié)
以上是生活随笔為你收集整理的数据库逻辑删除的sql语句_通过数据库的眼睛查询sql的逻辑流程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 梦到母鸡和小鸡是什么意思
- 下一篇: 数据挖掘流程_数据流挖掘