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

Posted 护花使者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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, COUNT(*) from t_cas_rural_selected GROUP BY county_code) 
as tTotal

如上,后面加个 as tablename 就可以了,例如:"as tTotal"

以上是关于mysql union出错: "Every derived table must have its own alias"的主要内容,如果未能解决你的问题,请参考以下文章

mysql union和union all的区别

Mysql union all select问题

MySQL使用union导致数据丢失的解决办法

mysql之内连接,外连接(左连接,右连接),union,union all的区别

PHP连接MySQL服务器老是出错

PHP MYSQL数据库连接出错