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