◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
有志者,事竟成!如果你在学习数据库,那么本文《我们如何通过从基表中选择某些范围的值来创建 MySQL 视图?》,就很适合你!文章讲解的知识点主要包括,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~
我们知道 MySQL BETWEEN 运算符可用于从某个值范围中选择值。我们可以使用 BETWEEN 运算符和视图来从基表中选择某些范围的值。为了理解这个概念,我们使用具有以下数据的基表“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”的视图,通过使用“BETWEEN”运算符选择特定范围内的某些值 -
mysql> Create or Replace view Info AS SELECT * from student_info WHERE Name BETWEEN 'C' AND 'P'; Query OK, 0 rows affected (0.14 sec) mysql> Select * from info; +------+--------+------------+------------+ | id | Name | Address | Subject | +------+--------+------------+------------+ | 105 | Gaurav | Chandigarh | Literature | | 133 | Mohan | Delhi | Computers | +------+--------+------------+------------+ 2 rows in set (0.00 sec)
同样,我们可以将 NOT 与 BETWEEN 运算符结合使用来选择与查询中写入的值不同的范围 -
mysql> Create or Replace view Info AS SELECT * from student_info WHERE Name NOT BETWEEN 'C' AND 'P'; Query OK, 0 rows affected (0.06 sec) mysql> Select * from Info; +------+---------+------------+-----------+ | id | Name | Address | Subject | +------+---------+------------+-----------+ | 101 | YashPal | Amritsar | History | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | +------+---------+------------+-----------+ 4 rows in set (0.00 sec)
终于介绍完啦!小伙伴们,这篇关于《我们如何通过从基表中选择某些范围的值来创建 MySQL 视图?》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~the24.cn也会发布数据库相关知识,快来关注吧!
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。