Home > Database > Mysql Tutorial > body text

sqlserver子查询报错

WBOY
Release: 2016-06-07 16:19:49
Original
1649 people have browsed it

sqlserver跟oracle对比,如果涉及到的子查询,则相应的表名、字段就必须命名一个别名才能执行。主要有两种情况: 1.查询sql里面只有简单子查询不包含分组、求和等待 eg:elect * from (select com_id from company) 如此会报错,必须加上外层加上别名,里层的

   sqlserver跟oracle对比,如果涉及到的子查询,则相应的表名、字段就必须命名一个别名才能执行。主要有两种情况:

  1.查询sql里面只有简单子查询不包含分组、求和等待 eg:elect * from (select com_id from company) 如此会报错,必须加上外层加上别名,,里层的select * from company这里可以加别名,也可以不加正确:select * from ( select com_id from company) a

  2.查询的sql里面包含分组、求和等或者其他函数时 eg:select * from (select com_id ,count( com_id) from company group by com_id ) a 这里如果给最外层sql加了别名,还是会报错,再给company 加上别名b select * from (select com_id,count(com_id) from company b group by com_id) a 这样也还是不行,因为其实count()函数的其实也可以当做一个子查询,所以也要给count()加上别名才行正确:select * from (select com_id ,count( com_id) c from company b group by com_id) a

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template