My query statement
Select COUNT (*) from (SELECT * from ...) Total
Error tips
Every derived table must have its own alias
Each derived table must have an alias of its own.
This error generally occurs when you are querying multiple tables.
Because the result of a subquery coming out of a nested query is as a derived table for the query at the top level, the result of the subquery must have an alias
Change the MySQL statement to: SELECT COUNT (*) from (SELECT * from ...) as total;
The problem is solved, although only one alias total without any effect is added, but this alias is required
The code is as follows |
|
Select Name1 name, java, JDBC, hibernate,total From (select Sc1.name name1, Sc1.mark Java From Student_course2 SC1 where sc1.course= ' Java ' as a, (select Sc2.name name2, Sc2.mark JDBC From Student_course2 SC2 where sc2.course= ' jdbc ' as B, (select Sc3.name name3, Sc3.mark hibernate From Student_course2 SC3 Where sc3.course= ' hibernate ') as C, (Select Sc4.name name4,sum (Sc4.mark) Total From Student_course2 SC4 GROUP by Sc4.name) as D where Name1=name2 and Name2=name3 and name3=name4 order by total ASC; The result is correct: +----------+------+------+-----------+-------+ | name | java | jdbc | hibernate | Total |< br> +----------+------+------+-----------+-------+ | wangwu | | | & nbsp; | 90 | | lisi | | | 50 |& nbsp; 180 | | Zhangsan | | | | 270 | +----------+------+------+-----------+-------+ 3 rows in Set (0.02 sec) |