Linux SQL statement Concise tutorial---CREATE VIEW

Source: Internet
Author: User

A view view can be used as a virtual table. It differs from the table in that there are actual data stored in the table, and that the view table is an architecture built on top of the table, which itself does not actually store the data.

The syntax for creating a view table is as follows:

CREATE VIEW "view_name" as "SQL statement";

"SQL statement" can be any of the SQL that we have mentioned in this textbook.

Take a look at an example. Suppose we have the following table:

Customer Table

Field name Type of information
First_Name CHAR (50)
Last_Name CHAR (50)
Address CHAR (50)
City CHAR (50)
Country CHAR (25)
Birth_date Datetime

To create a view of the three fields, including First_Name, last_name, and country, on this form, we enter

CREATE VIEW V_customer
As SELECT first_name, last_name, country
from Customer;

Now, we have a visual watch called V_customer :

v_customer View table

Field name Type of information
First_Name CHAR (50)
Last_Name CHAR (50)
Country CHAR (25)

We can also connect two tables using a view table. In this case, the user can find the information she wants directly from a view table, without having to make a connection action from two different tables. Suppose you have the following two tables:

store_information Form

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

Geography Form

Region_name Store_name
East Boston
East New York
West Los Angeles
West San Diego

We can use the following instructions to build a view table that includes sales for each region (sales):

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 view of the V_region_sales called a watch. This view list includes sales in different regions. If we're going to get the information from this view, we'll break in,

SELECT * from V_region_sales;

Results:

Region SALES
East 700
West 2050


Linux is measured as follows:







Reprint please specify: Xiao Liu

Linux SQL statement Concise tutorial---CREATE VIEW

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.