正在使用';任何';此处是必需的(sql)
嘿,我是sql语言的新手 我有一部电影(片名、年份、长度、颜色、学习时间、制片时间) 问题是(哪些电影比《乱世佳人》长?) 我想知道这两个答案之间是否有区别,哪一个是正确的,为什么正在使用';任何';此处是必需的(sql),sql,Sql,嘿,我是sql语言的新手 我有一部电影(片名、年份、长度、颜色、学习时间、制片时间) 问题是(哪些电影比《乱世佳人》长?) 我想知道这两个答案之间是否有区别,哪一个是正确的,为什么 select title from movie where length>any(select length from movie where title ='gone with the wind') select title from movie where length>(select le
select title
from movie
where length>any(select length from movie where title ='gone with the wind')
select title
from movie
where length>(select length from movie where title ='gone with the wind')
提前感谢
length>ANY()
表示length
需要高于select返回的一个(或多个)值。此选择可以返回多个值。只有当您知道select是单例select(即它只生成一行)时,才可以将其替换为()
。length>ANY()
意味着length
需要高于select返回的一个(或多个)值。此选择可以返回多个值。只有当您知道select是单例select(即它只生成一行)时,才可以将其替换为()
。如果title='gone with the wind'
有多个长度,则Any
将帮助您在子查询中查找其中任何一个长度较大的电影
select title
from movie
where length>any(select length from movie where title ='gone with the wind')
第二个查询只有在只有一个长度wheretitle='gone with the wind'
的情况下才能运行,否则它将抛出错误子查询返回多个值。它将获取长度大于子查询结果的电影
select title
from movie
where length>(select length from movie where title ='gone with the wind')
如果一部电影的长度超过一个,则选择第一个查询,否则使用第二个查询。如果title='gone with the wind'
的长度超过一个,则Any
将帮助您在子查询中查找长度大于其中任何一个长度的电影
select title
from movie
where length>any(select length from movie where title ='gone with the wind')
第二个查询只有在只有一个长度wheretitle='gone with the wind'
的情况下才能运行,否则它将抛出错误子查询返回多个值。它将获取长度大于子查询结果的电影
select title
from movie
where length>(select length from movie where title ='gone with the wind')
如果一部电影的长度超过一个长度,请选择第一个查询,否则请使用第二个查询。如果您知道标题是唯一的,请使用:
select title
from movie
where length > (select length from movie where title = 'gone with the wind');
使用any
有点误导,因为它意味着可能有多个匹配项
如果存在多个匹配项,我将使用:
select title
from movie
where length > (select min(length) from movie where title = 'gone with the wind');
或:
取决于我真正的意思
就个人而言,当与子查询一起使用时,我看不到关键字any
、some
和all
有任何用处。我认为使用聚合更容易理解结果查询,聚合使特定的比较更加明确。如果您知道标题是唯一的,请使用:
select title
from movie
where length > (select length from movie where title = 'gone with the wind');
使用any
有点误导,因为它意味着可能有多个匹配项
如果存在多个匹配项,我将使用:
select title
from movie
where length > (select min(length) from movie where title = 'gone with the wind');
或:
取决于我真正的意思
就个人而言,当与子查询一起使用时,我看不到关键字any
、some
和all
有任何用处。我认为使用聚合更容易理解结果查询,这使得特定的比较更加明确。在表movie中,标题“飘”的条目有多少?在表movie中,标题“飘”的条目有多少?