当前位置: 首页 > wzjs >正文

新公司如何做网站百度 营销推广怎么做

新公司如何做网站,百度 营销推广怎么做,网站开发与网页设计大作业,要建立网站作为运维工程师,熟练掌握聚合函数是进行数据分析和报表生成的基础技能。本文将系统讲解MySQL聚合函数的使用方法,包含大量实用示例和运维场景中的应用技巧。 1 常用聚合函数详解 1.1 基础聚合函数 1.1.1 SUM():求和计算 # 计算所有员工的工…
作为运维工程师,熟练掌握聚合函数是进行数据分析和报表生成的基础技能。本文将系统讲解MySQL聚合函数的使用方法,包含大量实用示例和运维场景中的应用技巧。

1 常用聚合函数详解

1.1 基础聚合函数

1.1.1 SUM():求和计算

# 计算所有员工的工资总和 
select sum(salary) from emp; 
# 计算销售部门的加班费总额 
select sum(overtime_pay) from test where department = 'sales';

1.1.2 AVG():平均值

# 计算公司平均薪资 
select avg(salary) from epm; 
# 计算技术部平均工龄(保留2位小数) 
select round(avg(years_of_service), 2) from epm where department = 'technology';

1.1.3 MAX()/MIN():极值查询

# 查询最高和最低工资 
select max(salary), min(salary) from epm; 
# 找出最近和最早上架的商品 
select max(create_time), min(create_time) from products;

1.1.4 COUNT():计数统计

# 统计员工总数 
select count(*) from epm; 
# 统计有邮箱的员工数量(不统计NULL) 
select count(email) from epm; 
# 统计不同部门的数量 
select count(distinct department) from epm;

1.2 运维场景应用案例

示例:监控表空间使用
# 统计各数据库占用空间(MB)
select table_schema, round(sum(data_length)/1024/1024, 2) as size_mb
from information_schema.tables 
group by table_schema;

2 聚合函数与GROUP BY分组

2.1 基础分组统计

# 按部门统计员工
select department, count(*) as employee_count,avg(salary) as avg_salary
from epm
group by department;# 商品分类统计
select category,count(*) as product_count,min(price) as min_price,max(price) as max_price,avg(price) as avg_price
from products
group by category;

2.2 多列分组

# 按部门和职位统计
select department, job_title,count(*) as headcount,sum(salary) as total_salary
from epm
group by department, job_title;

2.3. 运维实战案例

# 分析慢查询日志,按查询类型统计平均执行时间
select query_type,count(*) as query_count,avg(execution_time) as avg_time_ms
from slow_query_log
where log_date = curdate()
group by query_type;

3 HAVING子句过滤聚合结果

3.1 基础用法

# 筛选销售额大于1000的部门
select department, sum(sales) as total_sales
from sales_records
group by department
having sum(sales) > 1000;

3.2 复杂过滤条件

# 筛选平均工资高于公司平均的部门
select department,avg(salary) as dept_avg_salary
from epm
group by department
having avg(salary) > (select avg(salary) from epm);

3.3 运维监控应用

# 找出表空间超过1GB的数据库
select table_schema,round(sum(data_length)/1024/1024, 2) as size_mb
from information_schema.tables
group by table_schema
having size_mb > 1024
order by size_mb desc;

4 高级技巧与性能优化

4.1 WITH ROLLUP小计功能

select department,job_title,count(*) as headcount
from epm
group by department, job_title with rollup;

4.2 聚合函数性能优化

  • 为GROUP BY列添加索引
alter table epm add index idx_department (department);
  • 避免在WHERE中使用聚合函数
# 错误写法
select department, avg(salary) 
from epm 
where avg(salary) > 5000  # 这里会报错
group by department;# 正确写法
select department, avg(salary) 
from epm 
group by department
having avg(salary) > 5000;

4.3 聚合函数执行计划分析

explain 
select department, count(*) 
from epm 
group by department;

5 常见问题解决方案

5.1 问题1:GROUP BY与SELECT列不一致

# 错误示例
select employee_name, department, count(*)
from epm
group by department;# 正确写法
select department, count(*)
from epm
group by department;# 或者包含所有非聚合列
select employee_name, department, count(*) over (partition by department)
from epm;

5.2 问题2:NULL值处理

# COUNT(列名)会忽略NULL,COUNT(*)不会
select count(commission), count(*) 
from epm 
where department = 'sales';# 使用IFNULL处理
select department, avg(ifnull(commission, 0)) 
from epm
group by department;

6 总结

希望这篇指南能帮助您更好了解聚合函数以及更好地在MySQL运维工作中运用聚合函数!
http://www.dtcms.com/wzjs/411085.html

相关文章:

  • 做网站用什么语言比较简单google chrome官网下载
  • wordpress文章添加meta成都百度搜索排名优化
  • 大型网站开发前端准备怎么在百度上设置自己的门店
  • 最全的网页模板网站百度推广账号注册流程
  • js怎么做打开网站就复制内容济南网站制作平台
  • 家具网站建设方案互联网营销是什么意思
  • flash网站cmsb站推广引流最佳方法
  • 万网发布网站百度网盘免费下载
  • 网站一个人可以做吗培训心得简短50字
  • 设计类书籍网站爱站网关键词长尾挖掘
  • 家居企业网站建设机构乐天seo视频教程
  • 邹城有做网站的吗网址查询域名
  • 机关网站模板郴州网络推广外包公司
  • 宁都县建设局网站百度网址大全网站大全
  • 做一斗地主网站多少钱互动营销名词解释
  • 网站登录页面模板 下载体育热点新闻
  • 响应式网站 测试企业网站运营推广
  • 教育投资网站建设方案手机百度账号登录入口
  • 做网站业务的怎么寻找客户浏览器大全网站
  • 免费创建app网站谷歌浏览器下载安装2021最新版
  • 大学生做网站bt磁力搜索引擎索引
  • wordpress建站项目中国今天刚刚发生的新闻
  • 福建建设银行网站百度手机助手安卓版下载
  • 贵州网站建设公司推荐关键词优化的作用
  • 自己做网站在线看pdf关键词优化意见
  • 做国际生意的网站有哪些网站推广的营销策划方案
  • 南安网站设计搜索引擎营销的典型案例
  • 彩票站自己做网站微信推广怎么做
  • 网站建设公司首页快速搭建网站的工具
  • 烟台教育网站建设2022最近十大的新闻热点