Analyze the combined use of Aggregate functions and connection tables

Source: Internet
Author: User

Analyze the combination of the aggregate function and the connected table to see such a relation as MERS MERs (cust_id, cust_name, cust_contact) Orders (order_num, cust_id, order_date) If there is such a search statement: SQL code select cust_name, cust_contact, (select count (*) from Orders where Orders. cust_id = MERs. cust_id group by cust_id) from MERs: 1. you can retrieve the order quantity of each cust_id from the Orders table, because the isolated count (*) is aggregated based on the group by customer number. In addition, the join table operation is performed before aggregation. Connect orders and MERs. In this way, only the customer information is agreed internally and externally. 2. The outer layer lists other required customer information. Note: The inner layer is usually used as an isolated aggregate function. Before grouping operations on the inner layer, the connection conditions with the outer layer must be provided. The selection columns behind the outer select are basically in the outer table. To sum up, is this sentence a subquery or a normal connection. Obviously. It is a subquery that contains a select sentence in the select statement. Very special. clauses can be used as a search Column !~ That's it. In the future, we will try to group but involve two different tables.

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.