mysql like 运算符用于根据模式匹配选择数据。同样,我们可以将 like 运算符与视图结合使用,根据基表中的模式匹配来选择特定数据。为了理解这个概念,我们使用具有以下数据的基表“student_info” -
mysql> select * from student_info;+------+---------+------------+------------+| id   | name    | address    | subject    |+------+---------+------------+------------+| 101  | yashpal | amritsar   | history    || 105  | gaurav  | chandigarh | literature || 125  | raman   | shimla     | computers  || 130  | ram     | jhansi     | computers  || 132  | shyam   | chandigarh | economics  || 133  | mohan   | delhi      | computers  |+------+---------+------------+------------+6 rows in set (0.00 sec)
示例以下查询将创建一个名为“info”的视图,使用“like”运算符根据模式匹配选择一些特定值 -
mysql> create or replace view info as select * from student_info where name like '%ra%';query ok, 0 rows affected (0.11 sec)mysql> select * from info;+------+--------+------------+------------+| id   | name   | address    | subject    |+------+--------+------------+------------+| 105  | gaurav | chandigarh | literature || 125  | raman  | shimla     | computers  || 130  | ram    | jhansi     |  computers |+------+--------+------------+------------+3 rows in set (0.00 sec)
我们也可以将 not 与 like 运算符一起使用,如下 -
mysql> create or replace view info as select * from student_info where name not like'%ra%';query ok, 0 rows affected (0.14 sec)mysql> select * from info;+------+---------+------------+-----------+| id   | name    | address    | subject   |+------+---------+------------+-----------+| 101  | yashpal | amritsar   | history   || 132  | shyam   | chandigarh | economics || 133  | mohan   | delhi      | computers |+------+---------+------------+-----------+3 rows in set (0.00 sec)
以上就是我们如何通过从基表中基于模式匹配选择数据来创建mysql视图?的详细内容。
   
 
   