T-SQL Learning notes (1)

Source: Internet
Author: User
Notes
SELECT statement

The SELECT statement queries the data from the database by the specified criteria, including the following clauses:

SELECT clause

FROM clause

WHERE clause

Group BY clause

HAVING clause

ORDER BY clause

The following keywords are also included:

Null keyword

Like keyword

Cube keyword

Case key word

in keyword

OPENROWSET keyword



For some of the more familiar clauses and keywords here is not much to say, the following only write some unfamiliar.

Group BY clause

The GROUP BY clause mainly indicates the basis for grouping query results, and is usually used with aggregate functions (sum, max,min, etc.). For example: We can use the Sum function to calculate total sales for all stores, what if we want to calculate the total volume of each store? To do this we need to do two things: first, we need to query the store name and sales two fields, and then we use the SQL language group by command to group sales by different stores to calculate the total sales for different stores. The syntax format of the GROUP by command is: SELECT "column_name1", SUM ("Column_name2") from "table_name" GROUP BY "column_name1" we can use the following command to implement the For the purpose of this query: SELECT store_name, SUM (Sales) from Store_information GROUP by Store_name query results are displayed as: Store_name sum (Sal ES) Los Angeles $1800 San Diego $ Boston $700 Note: The GROUP by keyword is typically used to simultaneously query multiple fields and perform arithmetic on a field The SQL command for the operation.

HAVING clause

The HAVING clause, similar to where, is used specifically with group by to indicate conditions in group by.



Summary:

The Group by statement must generally have an aggregate function to classify the data. Having is specifically used to specify the conditions in the GROUP BY clause.


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.