This article uses examples to illustrate the usage of USING and HAVING in MySQL. Share with you for your reference, the details are as follows: USING Used to give join conditions when joining tables (which can be understood as abbreviated form), such as SELECT * FROM table1 JOIN table2 ON table1.id = table2.id Using USING can be written as SELECT * FROM table1 JOIN table2 USING (id) HAVING HAVING was introduced because WHERE cannot be used with statistical functions. For example, the order table has the following fields: id , date , price , customer To find customers whose order total is less than 2000, you can write: SELECT customer, SUM(price) FROM order GROUP BY customer HAVING SUM(price)<2000 Find the total order amount of orders exceeding 1500 for a specified customer: SELECT customer,SUM(price) FROM order WHERE customer = '…' OR customer = '…' GROUP BY customer HAVING SUM(price) > 1500 Readers who are interested in more MySQL-related content can check out the following topics: "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills". I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Solve the problem of case sensitivity of Linux+Apache server URL
>>: Solution to 404 error when downloading apk file from IIS server
Business requirements One of the projects I have ...
<br />In the field of network design, resear...
Assume that a node in the three-node MGR is abnor...
1. Alipay method: Alipay method: Click Alipay to ...
sftp is the abbreviation of Secure File Transfer ...
engine Introduction Innodb engine The Innodb engi...
When you write buttons (input, button), you will f...
Table of contents Math Objects Common properties ...
Table of contents Parent component listBox List c...
If you are looking to monitor your system interac...
Today's screen resolutions range from as smal...
There are caches everywhere inside MySQL. When I ...
1. Background 1.1 Problems A recent product testi...
About the invalid line-height setting in CSS Let&...
Upgrade process: Original system: CentOS7.3 [root...