Mysql LIKE 运算符用于根据模式匹配选择数据。同样,我们可以将 LIKE 运算符与视图结合使用,根据基表中的模式匹配来选择特定数据。为了理解这个概念,我们使用具有以下数据的基表“student_info” -mysql> Se
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)
--结束END--
本文标题: 我们如何通过从基表中基于模式匹配选择数据来创建MySQL视图?
本文链接: https://lsjlt.com/news/436231.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0