程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql “ Every derived table must have its own alias”呈現錯曲解決方法

mysql “ Every derived table must have its own alias”呈現錯曲解決方法

編輯:MySQL綜合教程

mysql “ Every derived table must have its own alias”呈現錯曲解決方法。本站提示廣大學習愛好者:(mysql “ Every derived table must have its own alias”呈現錯曲解決方法)文章只能為提供參考,不一定能成為您想要的結果。以下是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

這句話的意思是說每個派生出來的表都必需有一個自己的別名

普通在多表查詢時,會呈現此錯誤。

由於,停止嵌套查詢的時分子查詢出來的的後果是作為一個派生表來停止上一級的查詢的,所以子查詢的後果必需要有一一般名

把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)


感激閱讀,希望能協助到大家,謝謝大家對本站的支持!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved