SQL statement concise tutorial for linux --- CREATE VIEW, concise tutorial --- create
A View can be considered as a virtual table. Unlike a table, a table stores actual data, while a table is built on a table architecture and does not actually store data.
The syntax for creating a view table is as follows:
Create view "VIEW_NAME" AS "SQL statement ";
"SQL statement" can be any SQL statement we mentioned in this tutorial.
Let's look at an example. Suppose we have the following table:
CustomerTable
| Column name |
Data Type |
| First_Name |
Char (50) |
| Last_Name |
Char (50) |
| Address |
Char (50) |
| City |
Char (50) |
| Country |
Char (25) |
| Birth_Date |
Datetime |
To create a view table with three columns, First_Name, Last_Name, and Country,
Create view V_Customer
As select First_Name, Last_Name, Country
FROM Customer;
Now, we haveV_CustomerView table:
V_CustomerView table
| Column name |
Data Type |
| First_Name |
Char (50) |
| Last_Name |
Char (50) |
| Country |
Char (25) |
We can also use a view table to connect two tables. In this case, the user can find the information she wants directly from a view table, instead of having to perform a join operation in two different tables. Assume there are two tables:
Store_InformationTable
| Store_Name |
Sales |
Txn_Date |
| Los Angeles |
1500 |
05-Jan 1999 |
| San Diego |
250 |
07-Jan-1999 |
| Los Angeles |
300 |
08-Jan 1999 |
| Boston |
700 |
08-Jan 1999 |
GeographyTable
| Region_Name |
Store_Name |
| East |
Boston |
| East |
New York |
| West |
Los Angeles |
| West |
San Diego |
We can use the following command to create a view table that includes Sales for each Region:
Create view V_REGION_SALES
As select A1.Region _ Name REGION, SUM (A2.Sales) SALES
FROM Geography A1, Store_Information A2
WHERE A1.Store _ Name = A2.Store _ Name
Group by A1.Region _ Name;
This gives us a name namedV_REGION_SALES. This visual table contains sales in different regions. If we want to obtain information from this visual table, we will enter,
SELECT * FROM V_REGION_SALES;
Result:
| REGION |
SALES |
| East |
700 |
| West |
2050 |
Linux has been tested as follows:
Reprinted, please note: Xiao Liu