50金币
最佳答案> 1349 - View's SELECT contains a subquery in the FROM clause
这个错误是mysql视图中不支持有子查询
那我们可以将子查询先创建成一个视图,在将视图中进行统计
视图1:
SELECT name, num,total FROM table1
UNION ALL -- 不去重,用UNION ALL;去重,用UNION
SELECT name, num,total FROM table2
视图2:
SELECT name, SUM(num) AS 数量,SUM(total) AS 总数
FROM 视图1
GROUP BY name
| |
| |
| |
| |
| |
| |
| |
| |