MySQL Sub-query

Source: Internet
Author: User

The select sentence that appears in other SQL statements. (Nested select in select)

#求出学生的平均年龄
Select AVG (age) from Stu_details;

#查找出大于平均年龄的数据
Mysql> SELECT * from Stu_details where >18.25;

#将平均数的SQL语句作为子查询放入上一条语句中
Mysql> SELECT * from Stu_details where > (select AVG (age) from stu_details);

Example:

# #需求: To find, computer and foreign language students
Select d_id from department where D_name in (' Computer Academy ', ' Foreign Language Institute ')
# # sub-query
SELECT * FROM student where dept_id in (select d_id from department where D_name in (' Computer Academy ', ' Foreign Language Institute '));

MySQL Sub-query

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.