How to create a View Table with SQL statement
This article introduces the relevant knowledge of "how to use SQL sentences to create a view table". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Visual tables (Views) can be treated as virtual tables. Unlike a table, there is actual data stored in the table, while the visual table is a structure based on the table, which does not actually store the data. The syntax for creating a view table is as follows:
CREATE VIEW "VIEW_NAME" AS "SQL statement"
The "SQL statement" can be any SQL that we have mentioned in this textbook. Let's look at an example. Suppose we have the following table:
TABLE Customer
(First_Name char (50)
Last_Name char (50)
Address char (50)
City char (50)
Country char (25)
Birth_Date date)
To create a visual table on this table that includes the three fields First_Name,Last_Name and Country, we enter:
CREATE VIEW V_Customer
AS SELECT First_Name, Last_Name, Country
FROM Customer
Now, we have a visual table called V_Customer:
View V_Customer
(First_Name char (50)
Last_Name char (50)
Country char (25))
We can also use visual tables to connect two tables. In this case, the user can find out the information she wants directly from a visual table without having to do a join action from two different tables. Suppose you have the following two tables:
Store_Information form
Store_name sales date
Los Angeles $1500 jan-05-1999
San Francisco $300 jan-08-1999
Boston $700 jan-08-1999
Geography form
Region_name store_name
East Boston
East New York
West Los Angeles
West San Diego
We can use the following instructions to create a visual table that includes sales (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 visual table called V_REGION_SALES. This view table contains sales from different regions. If we want to get data from this view table, we enter:
SELECT * FROM V_REGION_SALES
Results:
REGION SALES
East $700
West $2050
This is the end of the content of "how to create a view table with SQL statement". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!