我们如何通过从基表中选择某些范围的值来创建 MySQL 视图?

2023年 8月 27日 31.7k 0

我们如何通过从基表中选择某些范围的值来创建 MySQL 视图?

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 视图?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论