好的,我正在将一个数据库从Server (我已经错过了)移动到MySql 5.6。我在创建一个有效日期列表时遇到了问题。在Server中,我只是使用CTE来建立数字,然后是月份,然后是数年,然后是一个月中的几天,然后交叉连接到一起创建一个有效的列表。我宁愿这样做,然后创建一个巨大的表,列出从开始到结束的所有有效日期。然而,将其转换为一组视图似乎不起作用:
create view `Numbers` as
select 0 N union all select 1 union all select 2 union all
select 3 union all select 4 union all select 5 union all
select 6 union all select 7 union all select 8 union all select 9;
create view `Months` as
select n.N+1 MonthNum union all select 11 union all select 12
from `Numbers` n;来自MySql的错误:错误代码: 1109。字段列表中的未知表n。
发布于 2013-03-14 18:01:47
您必须将第二个视图重写如下:
create view `Months` as
select N+1 MonthNum from `Numbers`
union all select 11
union all select 12
;这是证据
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.10-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use test
Database changed
mysql> create view `Numbers` as
-> select 0 N union all select 1 union all select 2 union all
-> select 3 union all select 4 union all select 5 union all
-> select 6 union all select 7 union all select 8 union all select 9;
Query OK, 0 rows affected (0.05 sec)
mysql> create view `Months` as
-> select N+1 MonthNum from `Numbers`
-> union all select 11
-> union all select 12
-> ;
Query OK, 0 rows affected (0.03 sec)
mysql>查看查询的输出
mysql> select * from Months;
+----------+
| MonthNum |
+----------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
| 11 |
| 12 |
+----------+
12 rows in set (0.00 sec)
mysql>试试看!!
https://dba.stackexchange.com/questions/36714
复制相似问题