SQL 什么是投影和选择?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1031076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are projection and selection?
提问by Erich Kitzmueller
What is the difference between projection and selection? Is it:
投影和选择有什么区别?是吗:
- Projection --> for selecting the columns of table; and
- Selection ---> to select the rows of table?
- 投影 --> 用于选择表的列;和
- 选择 ---> 选择表的行?
So are projection and selection vertical and horizontal slicing respectively?
那么投影和选择分别是垂直切片和水平切片吗?
回答by Erich Kitzmueller
Exactly.
确切地。
Projectionmeans choosing which columns(or expressions) the query shall return.
投影意味着选择 查询应返回哪些列(或表达式)。
Selectionmeans which rowsare to be returned.
选择意味着要返回哪些行。
if the query is
如果查询是
select a, b, c from foobar where x=3;
then "a, b, c" is the projection part, "where x=3" the selection part.
那么“a,b,c”是投影部分,“其中x=3”是选择部分。
回答by Harimohan Pandey
Simply PROJECTIONdeals with elimination or selection of columns, while SELECTION deals with elimination or selection of rows.
简单地PROJECTION处理列的消除或选择,而SELECTION处理行的消除或选择。
回答by AlluriReddy
Projection:what ever typed in select clause i.e, 'column list' or '*' or 'expressions' that becomes under projection.
投影:在 select 子句中输入的内容,即“列列表”或“*”或“表达式”,这些内容将被投影。
*selection:*what type of conditions we are applying on that columns i.e, getting the records that comes under selection.
* selection:*我们在该列上应用什么类型的条件,即获取选择的记录。
For example:
例如:
SELECT empno,ename,dno,job from Emp
WHERE job='CLERK';
in the above query the columns "empno,ename,dno,job" those comes under projection, "where job='clerk'" comes under selection
在上面的查询中,列“empno,ename,dno,job”属于投影,“where job='clerk'”属于选择
回答by Arnab
Projections and Selections are two unary operations in Relational Algebra and has practical applications in RDBMS (relational database management systems).
投影和选择是关系代数中的两个一元运算,在 RDBMS(关系数据库管理系统)中有实际应用。
In practical sense, yes Projection means selecting specific columns (attributes) from a table and Selection means filtering rows (tuples). Also, for a conventional table, Projection and Selection can be termed as vertical and horizontal slicing or filtering.
实际上,是的投影意味着从表中选择特定的列(属性),而选择意味着过滤行(元组)。此外,对于传统表格,投影和选择可以称为垂直和水平切片或过滤。
Wikipedia provides more formal definitions of these with examples and they can be good for further reading on relational algebra:
维基百科通过示例提供了更正式的定义,它们有助于进一步阅读关系代数:
- Projection: https://en.wikipedia.org/wiki/Projection_(relational_algebra)
- Selection: https://en.wikipedia.org/wiki/Selection_(relational_algebra)
- Relational Algebra: https://en.wikipedia.org/wiki/Relational_algebra