mysql“ Every derived table must have its own alias”问题
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-01 21:51:15 浏览: 评论:0
在mysql中查询时发现mysql提示Every derived table must have its own alias错误了,意思就是要有一个别名了,这个问题就这么解决了.
我的查询语句:select count(*) from (select * from ……) total;
错误提示:Every derived table must have its own alias
这句话的意思是说每个派生出来的表都必须有一个自己的别名,一般在多表查询时,会出现此错误.
因为,进行嵌套查询的时候子查询出来的的结果是作为一个派生表来进行上一级的查询的,所以子查询的结果必须要有一个别名.
把MySQL语句改成:select count(*) from (select * from ……) as total;
问题就解决了,虽然只加了一个没有任何作用的别名total,但这个别名是必须的,代码如下:
- 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 --phpfensi.com
- 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;
结果正确:
- +----------+------+------+-----------+-------+
- | name | java | jdbc | hibernate | total |
- +----------+------+------+-----------+-------+
- | wangwu | 40 | 30 | 20 | 90 |
- | lisi | 70 | 60 | 50 | 180 |
- | zhangsan | 100 | 90 | 80 | 270 |
- +----------+------+------+-----------+-------+
- 3 rows in set (0.02 sec)
Tags: Every derived table must
相关文章
- ·mysql中Table is read only错误解决方法(2014-09-22)
- ·mysql Copying to tmp table on disk 影响性能(2014-09-23)
- ·解决MySql error #1036 Table is read only 错误方法(2014-09-24)
- ·mysql关闭skip-grant-tables快速重置mysql密码(2014-09-27)
- ·mysql The table‘xxxx’is full 设置临时表大小(2014-09-28)
- ·MySQL无法重启提示Warning: World-writable config file(2014-09-28)
- ·MYSQL中OPTIMIZE TABLE优化使用方法(2014-10-01)
- ·MySQL的lock tables和unlock tables使用详解(2014-10-02)
- ·mysql中TRUNCATE TABLE 语句用法详解(2014-10-02)
- ·mysql Can t create new tempfile: tablename.TMM(2014-10-08)
- ·mysql中Incorrect key file for table: Try to repair it(2014-10-09)
- ·phpadmin导入数据提示lock tables tablename write(2014-10-10)
- ·利用--skip-grant-tables找回忘记mysql密码方法(2014-10-10)
- ·mysql中Table is read only的解决方法总结(2014-10-12)
- ·mysql提示[Warning] Invalid table or database name(2014-10-13)
- ·fail1Table “.\xxx\xxx” is marked as crashed and should be repaired(2014-10-14)

推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)