(3.13) T-SQL simple query

Source: Internet
Author: User

1. General Enquiry:

SELECT * FROM Info #查询Info all the contents of the table

Select Name,code from Info #查询Info table Name,code Column

2. Conditional query

SELECT * from Info where sex=1# query for cells with Sex 1 in the info table

SELECT * from Info where sex=1 and nation= ' n001 ' #查询Info表中Sex = 1 and nation=n001 data

SELECT * from Info where sex=1 or nation= ' n001 ' #查询Info表中Sex =1 or nation=n001 data

3. Fuzzy query

SELECT * from chinastates where areaname like ' in% ' #查询Chinastates表 data starting in the AreaName column

SELECT * from chinastates where areaname like '% in% ' #查询ChinaStates表中AreaName列中包含中的数据

SELECT * from chinastates where areaname like ' _ in% ' #查询ChinaStates表中AreaName列中第二个字为中的数据

4. Sort queries

SELECT * from Car ORDER BY Code Desc #查询Car表中按Code列降序排列

SELECT * from Car ORDER by Code ASC #查询Car表中按Code列升序排列

SELECT * FROM Car order by Code, brand# query Car table in Code,brand arrangement

5. Statistical queries (aggregation functions)

Select COUNT (oil) from Car #查询Car the number of rows in the oil column in the table

Select Max from Car #查询Car表中Oil列中最大的数据

Select min (oil) from Car #查询Car表中Oil列中最小的数据

Select Avg. from Car #查询Car表中Oil列数据的平均值

6. Group queries

Select Code,brand, COUNT (*) from car GROUP by brand# query the car table for groups to view the number of data bars per group

SELECT * FROM Car GROUP by Brand have Count (*) >1 #查询Car表中分组查看Brand中数据条数大于2的

7. Paging Query

SELECT * from Car limit 5,5 #查询Car表中跳过5条数据取5条数据

(3.13) T-SQL simple query

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.