Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 选择一个数字意味着什么?_Mysql_Sql_Algorithm_Database Design_Tree - Fatal编程技术网

Mysql 选择一个数字意味着什么?

Mysql 选择一个数字意味着什么?,mysql,sql,algorithm,database-design,tree,Mysql,Sql,Algorithm,Database Design,Tree,我正在看我书中的一个例子,SQL反模式。示例表是 TreePaths ============================== ancestor | descendant ------------------------------ 1 1 1 2 1 3 1 4 1 5 1

我正在看我书中的一个例子,SQL反模式。示例表是

         TreePaths
==============================
    ancestor | descendant
------------------------------
       1          1
       1          2 
       1          3
       1          4
       1          5
       1          6
       1          7
       2          2
       2          3
       3          3
       4          4
       4          5
       4          6
       4          7
       5          5
       6          6
       6          7
       7          7
我对此感到困惑

INSERT INTO TreePaths (ancestor, descendant)
   SELECT t.ancestor, 8
   FROM TreePaths AS t
   WHERE t.descendant = 5
 UNION ALL
   SELECT 8,8
首先让我了解一下这个子查询

SELECT t.ancestor, 8
FROM TreePaths AS t
WHERE t.descendant = 5
这应该会回来

t.ancestor  |   ???? 
---------------------
   5              ?
   5              ?
   5              ?
t.ancestor  |   8 
---------------------
   1              8
   4              8
   5              8
我想

SELECT x, y

这意味着
x
y
是名称或列,
8
不是列的名称。这到底是怎么回事?

在这种情况下,它们实际上只是表示数字,这些是文字。既然您标记了MySql,就可以检查它

因此子查询将返回

t.ancestor  |   ???? 
---------------------
   5              ?
   5              ?
   5              ?
t.ancestor  |   8 
---------------------
   1              8
   4              8
   5              8
考虑到账户中的工会,它将返回

t.ancestor  |   8 
---------------------
   1              8
   4              8
   5              8
   8              8
t.ancestor   |   8
------------------
  1              8
  4              8
  5              8

在这种情况下,它们实际上只是表示数字,这些是文字。既然您标记了MySql,就可以检查它

因此子查询将返回

t.ancestor  |   ???? 
---------------------
   5              ?
   5              ?
   5              ?
t.ancestor  |   8 
---------------------
   1              8
   4              8
   5              8
考虑到账户中的工会,它将返回

t.ancestor  |   8 
---------------------
   1              8
   4              8
   5              8
   8              8
t.ancestor   |   8
------------------
  1              8
  4              8
  5              8

在这种情况下,查询应该返回

t.ancestor  |   8 
---------------------
   1              8
   4              8
   5              8
   8              8
t.ancestor   |   8
------------------
  1              8
  4              8
  5              8

您正在选择t.consent,其中子代为=5

,在这种情况下,查询应该返回

t.ancestor  |   8 
---------------------
   1              8
   4              8
   5              8
   8              8
t.ancestor   |   8
------------------
  1              8
  4              8
  5              8

选择t。其中,子代为=5

x
y
是表中每行计算一次的表达式,其值被视为当前行中的对应列
8也是一个表达式,每行计算一次,其值取常量“8”

在这种情况下,查询将返回

t.ancestor   |   8
------------------
  1              8
  4              8
  5              8

正如scaisEdge所观察到的。

x
y
是表中每行计算一次的表达式,其值被视为当前行中的对应列
8也是一个表达式,每行计算一次,其值取常量“8”

在这种情况下,查询将返回

t.ancestor   |   8
------------------
  1              8
  4              8
  5              8

正如scaisEdge观察到的那样。

然后选择8,8
只返回。。。什么?它只返回值8,8。。取决于where子句的行数。如果运行
select8,8 fromtreepaths作为t,其中t.genderant=5
您将得到三行,其中有两个值,8,8Ah,我认为
WHERE
子句只应用于它出现的子查询。我认为这是两个独立的查询,(1)
SELECT t.sensort,8 FROM treepath作为t,其中t.genderant=5
,(2)
SELECT 8,8
,其结果行然后与
UNION ALL
组合。这不对吗?是的,没错:)我只是把这个条件作为一个例子来演示你会得到多少条记录,然后
选择8,8
只返回。。。什么?它只返回值8,8。。取决于where子句的行数。如果运行
select8,8 fromtreepaths作为t,其中t.genderant=5
您将得到三行,其中有两个值,8,8Ah,我认为
WHERE
子句只应用于它出现的子查询。我认为这是两个独立的查询,(1)
SELECT t.sensort,8 FROM treepath作为t,其中t.genderant=5
,(2)
SELECT 8,8
,其结果行然后与
UNION ALL
组合。这不对吗?是的,没错:)我只是把这个条件作为一个例子来说明你会得到多少条记录