Some personal understanding of SQL statement queries in SQL Server

Source: Internet
Author: User
Tags dname

As a programmer, it's really hard to have any insight, that is, to some people who have just learned to program, hoping to give them some help!

SQL Server is not too difficult to get started as a database for beginners to learn! In other words, building a library, building tables, building constraints, database tables to increase the deletion of the search!

But today is mainly about the query, the most important is the most difficult part!

First of all, look at this piece of code:

Select Dname as counties, SNAME as streets, Hos_type. Htid as type, price as, CONTENTS as description, COPY as memo from Hos_house left outer
Join Sys_user on Sys_user. Uid=hos_house. Uid
Join Hos_street on Hos_street. Sid=hos_house. Sid
Join Hos_district on Hos_district. Did=hos_street. Sdid
Join Hos_type on Hos_type. Htid=hos_house. Htid
and Hos_house. UID in
(
Select UID from Sys_user where Uname= ' Zhang San '
)

This code uses the left Outer connection query, inquires the Zhang San all housing information!

Select Top 5 * from Hos_house where
(
Hmid not in
(
Select Top 5 hmid from Hos_house ORDER by Hmid
)
)

It's a simple paging!

Select Htname as type, UNAME as name, dname as County, SNAME as street from hos_house left outer
Join Sys_user on Sys_user. Uid=hos_house. Uid
Join Hos_street on Hos_street. Sid=hos_house. Sid
Join Hos_district on Hos_district. Did=hos_street. Sdid
Join Hos_type on Hos_type. Htid=hos_house. Htid
where Hos_district. did in
(
Select Sdid from Hos_street where Sdid in
(
Select SID from Hos_house Group by SID have (COUNT (*) >=1)
) Group by Sdid have (COUNT (*) >=2)
) Order BY Sdid

This code is more difficult, query the street, the community at least a community, a cell at least two rental information, this code to understand not difficult, it is rare to write whether you want to be thoughtful!

Some personal understanding of SQL statement queries in SQL Server

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.