Mysql碰到“Every derived table must have its own alias”类似错误说明

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

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)

时间: 2024-09-28 13:28:06

Mysql碰到“Every derived table must have its own alias”类似错误说明的相关文章

mysql出现错误“ Every derived table must have its own alias”

Every derived table must have its own alias 这句话的意思是说每个派生出来的表都必须有一个自己的别名 一般在多表查询时,会出现此错误. 因为,进行嵌套查询的时候子查询出来的的结果是作为一个派生表来进行上一级的查询的,所以子查询的结果必须要有一个别名 问题就解决了,虽然只加了一个没有任何作用的别名total,但这个别名是必须的

Every derived table must have its own alias

今天写一个mysql语句 SELECT `A` a FROM (SELECT dt.`A` FROM `db`.`table` dt ) 其实是一个简单的嵌套查询,但是就报错了 “Every derived table must have its own alias”. 我英语不太好,就去百度翻译了一下这句话,意思是“每个派生出来的表都必须有一个自己的别名”,可以把括号里面的查询语句的结果集理解为新派生的一个表和数据,要从这个派生表中查询数据就必须给这个派生表取一个别名 SELECT B.`A`

错误代码: 1248 Every derived table must have its own alias

1.错误描述 1 queries executed, 0 success, 1 errors, 0 warnings 查询:SELECT stu_id, (SELECT stu_name FROM t_student_info t WHERE t.stu_id = t.stu_id) stu_name FROM (SELECT SUM( CASE course WHEN '敮.. 错误代码: 1248 Every derived table must have its own alias 执行耗

mysql union出错: "Every derived table must have its own alias"

SELECT count(*) from (SELECT province_code as area_id, count(*) from t_cas_rural_selected GROUP BY province_code UNION all SELECT city_code as area_id, COUNT(*) from t_cas_rural_selected GROUP BY city_code UNION all SELECT county_code as area_id, COU

MySQL 派生表(Derived Table) Merge Optimization

本文将通过演示告诉你:MySQL中派生表(Derived Table)是什么?以及MySQL对它的优化. Background 有如下一张表: mysql> desc city; +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-

MYSQL导入数据:Table XXX doesn't exist的解决

数据表为Innodb引擎 data文件夹中存在数据表的frm文件,但在phpmyadmin中看不到这些表,于是采用导入sql文件的方式进行恢复 1.直接导入原数据表的sql文件,原frm文件不删除 出错:#1146 - Table 'eticket.et_admin' doesn't exist 2.删除原frm文件,刷新phpmyadmin,再导入该数据表的sql文件 出错:#1146 - Table 'eticket.et_admin' doesn't exist 3.删除原frm文件,重启

MySQL出现Waiting for table metadata lock的原因以及解决方法

转自:http://ctripmysqldba.iteye.com/blog/1938150 (有修改) MySQL在进行alter table等DDL操作时,有时会出现Waiting for table metadata lock的等待场景.而且,一旦alter table TableA的操作停滞在Waiting for table metadata lock的状态,后续对TableA的任何操作(包括读)都无法进行,因为他们也会在Opening tables的阶段进入到Waiting for

detecting locked tables mysql (locked by LOCK TABLE)

detecting locked tables mysql (locked by LOCK TABLE) up vote15down votefavorite 7 I would like to know whether there is an option to detect locked tables in mysql or not. I mean locked by LOCK TABLE table WRITE/READ command? mysql locking share|impro

A MySQL foreign keys drop table, re-create table example

Summary: How to drop MySQL database tables and recreate them when you have foreign keyrelationships between the tables. This is pretty obscure, but I thought I'd post it here so I wouldn't forget how to do this ... if you ever have a situation when u