SQL statement concise tutorial for linux --- CREATE VIEW, concise tutorial --- create

Source: Internet
Author: User

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

Related Article

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.