7, SQL Basic collation (sub-query)

Source: Internet
Author: User

Sub-query

(used for querying between two tables, etc.)

The query inside the parentheses can only display information for one column

Select *from haha where age in (

Select MAX (age) from haha where bumen = ' sales Department '

) and Bumen in (

Select Bumen from haha group by bumen have COUNT (*) >5)

---Practice: The information of the first, the person according to the age from small to large

Select top 3 *from haha where code not in (

Select Top 5 code from haha order by age)

ORDER BY age

-----------Paging--------------

Select top 5*from haha where code not in (select Top ten code from haha)

----------a table How many pages can be divided by the specified number of entries (5)----------

Select Ceiling (COUNT (*)/5.0) from haha

(Cannot use 5 integral type, to prevent auto default to int type)

7, SQL Basic collation (sub-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.