Mysql 选择一个数字意味着什么?
我正在看我书中的一个例子,SQL反模式。示例表是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
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
组合。这不对吗?是的,没错:)我只是把这个条件作为一个例子来说明你会得到多少条记录