Sqlsever Query Basic

Source: Internet
Author: User

Query statement:

SQL Sever query statement;

1. Query all fields:

SELECT * FROM UserInfo

2. Conditional screening

(such as querying the username in userinfo)

Select UserName from UserInfo

  WHERE statement:

SELECT * from UserInfo where sex= ' man ' and major= ' computer ' (and/or)

Top statement: Top 5* ... order by ... desc (desc marked descending-not written is ascending ) Note (number plus *) Brder by

Select Top UserInfo from the Where major= ' computer ' ORDER BY age DESC

Max: Query for the maximum number of values ( such as the oldest in the age field of the query )

Select Max(age) from UserInfo

Minimum-----min avg Avg

Sum: Sum (as follows, query age sum)

Select SUM(age) from UserInfo

count: Quantity ( such as the number of students who have computer majors found in all data )

Select Count(*) from UserInfo where major= ' computer '

As : Give the queried field an individual name, convenient for later use ( such as the above query results named UserCount)

Select COUNT (*) as UserCount from UserInfo where major= ' computer '

GROUP BY: Query result grouping () having Count (*) >3 (where cannot be used at this time)

Select COUNT (*) as Groupcount,major from UserInfo group by Major have count (*) >3

Like: Fuzzy query

SELECT * from UserInfo where reaname like '% sheet% '

Sqlsever Query Basic

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.