如何基于另一个现有视图创建 MySQL 视图?
mysqlmysqli database
在 MySQL 中,我们可以基于另一个现有视图创建视图。为了便于理解,我们拥有包含以下数据的视图"Info" −
mysql> Create view info AS Select Id, Name, Subject FROM student_info; Query OK, 0 rows affected (0.11 sec) mysql> Select * from Info; +------+---------+------------+ | Id | Name | Subject | +------+---------+------------+ | 101 | YashPal | History | | 105 | Gaurav | Literature | | 125 | Raman | Computers | | NULL | Ram | Computers | +------+---------+------------+ 4 rows in set (0.00 sec)
现在,借助以下查询,我们将基于现有视图‘info’创建另一个视图名称‘info_less’,该视图 −
mysql> Create view info_less AS Select Id, Name, Subject FROM info WHERE id >= 120; Query OK, 0 rows affected (0.25 sec) mysql> Select * from info_less; +------+-------+-----------+ | Id | Name | Subject | +------+-------+-----------+ | 125 | Raman | Computers | +------+-------+-----------+ 1 row in set (0.03 sec)