SQL select statement usage

Source: Internet
Author: User

Select statements are used to select data from a table.

Results are stored in a result table (called a result set ).

SQL select syntax
Select column name from Table Name and:

Select * from table name Note: SQL statements are case-insensitive. Select is equivalent to select.
SQL select instance
To obtain the content of columns named "lastname" and "firstname" (from the database tutorial table named "persons"), use a select statement like this:

Select lastname, firstname from persons

When the select function is used, a set of qualified records is retrieved from the dataset and expanded in cells. At this time, each extended cell retains a pointer pointing to the current record, that is, the current row. Therefore, in the affiliated cells of these cells, you should directly use"Dataset name.Column name"To reference the value of the same record in the same dataset. In this case, the report engine does not need to retrieve and traverse the dataset, but directly takes the value from the current row.

Figure:

 

Typical select usage:

 

 

Unreasonable usage:

 

 

Since there are a lot of data in the database that already has numbers, a very important purpose is to be able to perform some operations on these numbers, such as sum them up, or find out their average value. SQL provides some such functions. They are:


Avg (average)
Count)
Max (maximum)
Min (minimum)
Sum (sum)
The syntax for using functions is:

Select "function name" ("column name ")
From "table name"


For example, if we want to find the sum of the sales field in our example table,

Store_information table
Store_name sales date
Los angeles $1500 jan-05-1999
San diego $250 jan-07-1999
Los angeles $300 jan-08-1999
Boston $700 jan-08-1999

 

Let's get,


Select sum (sales) from store_information

 

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.