Get the App
SLTechnology News&Howtos  ›  Database  › 

A brief Analysis of the examples of USING and HAVING usage in MySQL

Shulou Source: shulou.com Published: 2022-06-01 04:10:40 10月26日 Update

This paper gives an example of the usage of USING and HAVING in MySQL. Share with you for your reference, the details are as follows:

USING

For table joins given join conditions (which can be understood as shorthand), such as

SELECT * FROM table1JOIN table2 ON table1.id = table2.id

Using USING, you can write as

SELECT * FROM table1JOIN table2 USING (id)

HAVING

HAVING was introduced because WHERE cannot be used with statistical functions

For example, table order (order) has the following fields:

Id, date, price, customer

To find customers with a total order of less than 2000, you can write:

SELECT customer, SUM (price) FROM orderGROUP BY customerHAVING SUM (price) 1500

More readers who are interested in MySQL-related content can check out this site's special topics: "A Summary of MySQL Common functions", "A Collection of MySQL Log Operation skills", "MySQL transaction Operation skills Summary", "MySQL stored procedure skills Collection" and "MySQL Database Lock related skills Summary"

It is hoped that what is described in this article will be helpful to everyone's MySQL database design.

Tags: Skills orders functions Daquan customers totals data databases instances topics transactions interests contents fields orders commonly used forms logs more conditions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info MariaDB Microsoft OPPO Reno