Article Topic Learning Download Q&A Programming Dictionary Game Recent Updates
LOGIN
简体中文(ZH-CN) English(EN) 繁体中文(ZH-TW)
  • PHP Development
  • Large Front-end
  • Back-end Development
  • Database
  • Mobile Terminal
  • Operation and Maintenance Development
  • Ui Design
  • Fundamentals of Computer Science
Home > Database > Mysql Tutorial > body text

How to use having in SQL?

Guanhui
Release: 2020-06-05 15:48:42
Original
20101 people have browsed it

How to use having in SQL?

How to use having in SQL?

"Having" is used to filter statistics after "group by". Generally, "having" will be used together with "group by". When using it, you must first group by "group by" and then proceed. "Having" statistical filtering, such as determining whether the value of an aggregate function is greater than a certain value.

SQL Example

1. Display the total population and total area of ​​each region.

SELECT region, SUM(population), SUM(area) FROM bbc GROUP BY region
Copy after login

First divide the returned records into multiple groups by region. This is the literal meaning of GROUP BY. After grouping, use aggregate functions to operate on different fields (one or more records) in each group.

2. Display the total population and total area of ​​each region. Only those areas with an area greater than 1,000,000 are shown.

SELECT region, SUM(population), SUM(area)
FROM bbc
GROUP BY region
HAVING SUM(area)>1000000
Copy after login

Here, we cannot use where to filter regions with more than 1,000,000, because such a record does not exist in the table.

On the contrary, the having clause allows us to filter each group of data into groups

mysql determines the length of a certain field:

select home_page from aaa表 where char_length(trim(home_page))<10 and char_length(trim(home_page))>1;
Copy after login

Recommended tutorial: "

MySQL Tutorial

两个鬼故事大气超市起名字她他社给你未来属猪陈起名用睿起名字好侯姓起名大全咖啡公司起名字大全池子与笑果文化和解魔兽改男装店铺起名丈夫节八佰伴官网免费起店名字测试打分表大掌门2教父的荣耀543部队开店起的名好寓意的起名成语大全升国旗作文天涯国际观察黄秋生在台隔离期间被诈骗餐饮供应链公司起名鼠年李姓起名大全斩魂御兽psp王国之心沙龙娱乐场性感美女脱衣钦字起名什么含义个人取向电视剧日本极度色诱少年生前被连续抽血16次?多部门介入两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”淀粉肠小王子日销售额涨超10倍高中生被打伤下体休学 邯郸通报单亲妈妈陷入热恋 14岁儿子报警何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言张家界的山上“长”满了韩国人?男孩8年未见母亲被告知被遗忘中国拥有亿元资产的家庭达13.3万户19岁小伙救下5人后溺亡 多方发声315晚会后胖东来又人满为患了张立群任西安交通大学校长“重生之我在北大当嫡校长”男子被猫抓伤后确诊“猫抓病”测试车高速逃费 小米:已补缴周杰伦一审败诉网易网友洛杉矶偶遇贾玲今日春分倪萍分享减重40斤方法七年后宇文玥被薅头发捞上岸许家印被限制高消费萧美琴窜访捷克 外交部回应联合利华开始重组专访95后高颜值猪保姆胖东来员工每周单休无小长假男子被流浪猫绊倒 投喂者赔24万小米汽车超级工厂正式揭幕黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发当地回应沈阳致3死车祸车主疑毒驾恒大被罚41.75亿到底怎么缴妈妈回应孩子在校撞护栏坠楼外国人感慨凌晨的中国很安全杨倩无缘巴黎奥运校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变王树国卸任西安交大校长 师生送别手机成瘾是影响睡眠质量重要因素国产伟哥去年销售近13亿阿根廷将发行1万与2万面值的纸币兔狲“狲大娘”因病死亡遭遇山火的松茸之乡“开封王婆”爆火:促成四五十对奥巴马现身唐宁街 黑色着装引猜测考生莫言也上北大硕士复试名单了德国打算提及普京时仅用姓名天水麻辣烫把捣辣椒大爷累坏了

两个鬼故事 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化

The above is the detailed content of How to use having in SQL?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
mysql sql
source:php.cn
Previous article:What is the difference between phantom read and non-repeatable read? Next article:What is the main role of indexing in a database?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Latest Articles by Author
  • Is Taobao developed in Java or PHP?
    2023-03-03 16:08:02
  • What does PHP hook mean?
    2023-03-03 16:02:01
  • How to use substr function in PHP?
    2023-03-03 15:58:01
  • Office software is developed by which company?
    2020-07-31 13:42:10
  • What should I do if Win10 is not compatible with Steam?
    2020-07-31 13:29:12
  • How to make the table adjust automatically?
    2020-07-31 11:58:22
  • What counts as the same LAN?
    2020-07-31 11:38:07
  • What is the Paipapai function?
    2020-07-31 11:24:55
  • What are the consequences of not activating the system?
    2020-07-31 11:15:48
  • How to change a negative number in Excel with one click?
    2020-07-31 10:55:17
Latest Issues
How to list data in a section by ID using while loop in PHP? I have a mysql table with these columns: series_id, series_color, product_name In the outp...
From 2023-11-17 20:03:03
0 1 290
Using triggers and constraints to limit the number of records in MySQL I have a table called BFFs that stores user IDs and best friends' user IDs, and I want to ...
From 2023-11-14 13:35:02
0 4 434
Resolving django.db.utils.NotSupportedError error in Django I'm getting an error when running a project in Django. The problem is unfortunately I upgr...
From 2023-11-14 11:59:20
0 1 246
Retrieve MySql rows with the same column value Let us consider the following table - IDScore19521003884100573 I am a complete SQL noob, b...
From 2023-11-10 21:53:39
0 2 331
How to publish SQLite database data to an online MySQL database in Flutter? How to sync offline SQLite to MySQL online database in Flutter? Any suggestions?
From 2023-11-10 12:36:40
0 2 247
Related Topics
More>
  • mysql modify data table name
  • MySQL creates stored procedure
  • The difference between mongodb and mysql
  • How to check if mysql password is forgotten
  • mysql create database
  • mysql default transaction isolation level
  • The difference between sqlserver and mysql
  • mysqlforgot password
Popular Recommendations
  • How to uninstall mysql cleanly?
  • What does sql mean?
  • What is the sql add, delete, modify, query statement?
  • What are the differences between mysql and oracle?
  • what is database
Popular Tutorials
More>
Related Tutorials
Popular Recommendations
Latest courses
  • MySql Reference Manual
    MySql Reference Manual
    4989
    Collection
  • MySQL Optimization Video Tutorial—Boolean Education
    MySQL Optimization Video Tutorial—Boolean Education
    58359
    Collection
  • Apache and MySQL installation and use tutorial
    Apache and MySQL installation and use tutorial
    47060
    Collection
  • MySQL data management backup and recovery case analysis video tutorial
    MySQL data management backup and recovery case analysis video tutorial
    38613
    Collection
Latest Downloads
More>
  • Home Decor Cleaning and Repair Service Company Website Template
Web Effects
Website Source Code
Website Materials
Front End Template
  • [form button] jQuery enterprise message form contact code
  • [Player special effects] HTML5 MP3 music box playback effects
  • [Menu navigation] HTML5 cool particle animation navigation menu special effects
  • [form button] jQuery visual form drag and drop editing code
  • [Player special effects] VUE.JS imitation Kugou music player code
  • [html5 special effects] Classic html5 pushing box game
  • [Picture special effects] jQuery scrolling to add or reduce image effects
  • [Photo album effects] CSS3 personal album cover hover zoom effect
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!

两个鬼故事大气超市起名字她他社给你未来属猪陈起名用睿起名字好侯姓起名大全咖啡公司起名字大全池子与笑果文化和解魔兽改男装店铺起名丈夫节八佰伴官网免费起店名字测试打分表大掌门2教父的荣耀543部队开店起的名好寓意的起名成语大全升国旗作文天涯国际观察黄秋生在台隔离期间被诈骗餐饮供应链公司起名鼠年李姓起名大全斩魂御兽psp王国之心沙龙娱乐场性感美女脱衣钦字起名什么含义个人取向电视剧日本极度色诱少年生前被连续抽血16次?多部门介入两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”淀粉肠小王子日销售额涨超10倍高中生被打伤下体休学 邯郸通报单亲妈妈陷入热恋 14岁儿子报警何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言张家界的山上“长”满了韩国人?男孩8年未见母亲被告知被遗忘中国拥有亿元资产的家庭达13.3万户19岁小伙救下5人后溺亡 多方发声315晚会后胖东来又人满为患了张立群任西安交通大学校长“重生之我在北大当嫡校长”男子被猫抓伤后确诊“猫抓病”测试车高速逃费 小米:已补缴周杰伦一审败诉网易网友洛杉矶偶遇贾玲今日春分倪萍分享减重40斤方法七年后宇文玥被薅头发捞上岸许家印被限制高消费萧美琴窜访捷克 外交部回应联合利华开始重组专访95后高颜值猪保姆胖东来员工每周单休无小长假男子被流浪猫绊倒 投喂者赔24万小米汽车超级工厂正式揭幕黑马情侣提车了西双版纳热带植物园回应蜉蝣大爆发当地回应沈阳致3死车祸车主疑毒驾恒大被罚41.75亿到底怎么缴妈妈回应孩子在校撞护栏坠楼外国人感慨凌晨的中国很安全杨倩无缘巴黎奥运校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变王树国卸任西安交大校长 师生送别手机成瘾是影响睡眠质量重要因素国产伟哥去年销售近13亿阿根廷将发行1万与2万面值的纸币兔狲“狲大娘”因病死亡遭遇山火的松茸之乡“开封王婆”爆火:促成四五十对奥巴马现身唐宁街 黑色着装引猜测考生莫言也上北大硕士复试名单了德国打算提及普京时仅用姓名天水麻辣烫把捣辣椒大爷累坏了

两个鬼故事 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化