This article is a mirror article of machine translation, please click here to jump to the original article.

View: 12212|Reply: 0

[Communication] Usage of having in SQL

[Copy link]
Posted on 4/16/2015 6:05:23 PM | | |

The usage of having is similar to the usage of WHERE, but there are three differences
1. HAVING is only used for GROUP BY (group statistical statement),
2. WHERE is used to filter queries in the initial table, and HAVING is used to query in WHERE and GROUP BY results.
3. HAVING can use aggregation functions, but not WHERE faces.
The following statement counts users with the name "Li" (defined by the WHERE clause) in the user table and who appear more than once (having defined by the aggregation function COUNT(1)).
SELECT USERCODE,username=max(username),times=count(1) from usertable where username like 'Li%' group by usercode having count(1)>1




Previous:Perfect solution to the problem of slow Google fonts in WordPress links
Next:What are the types of data integrity not included?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com