在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_less'的新视图,该视图基于现有视图'info' -
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)