SQL模糊查询,sum,AVG,MAX,min函数
cmd
mysql -hlocalhost -uroot -p
select * from emp where ename like '___' -- 三个横线, - 代表字符,可以查询 三个ename是3个字符数据
select * from emp where job like '___员'; -- job是四个字符且以 员 字结尾
select * from emp where ename like 'm%'; --查询 ename 以 m 开头的记录,% 匹配 0 - n个任何字符
select * from emp where ename like '_u%'; -- 查询 ename 中第二个字符为 u 的记录
select * from emp where ename like '%s%'; -- 查询 ename 中包含 s 的记录
IFNULL(expr1,expr2),如果 expr1 为 null ,则 expr1 = expr2
select *,IFNULL(score1,0) + IFNULL(score2,0) form emp; --如果score1为null ,则score1 = 0

常用聚合函数

count
select count(*) from emp; -- 统计记录数
select count(ename) from emp; -- 统计ename 记录数,该记录字段为NULL则不统计在内
-- 统计员工表总salary大于 2500 的人数
select count(*) from emp where salary > 2500;
-- 统计 salary 与 performance 之和大于 5000 的人数
select count(*) from emp where salart + IFNULL(performance,0) > 5000 ; -- performance可能会为null,如果为null ,就替换为 0
sum AVG MAX min
-- 查询 salary 之和
select sum(salary) from emp;
-- 查询 salary之和,performance之和
select sum(salary), sum(performance) form emp;
-- 查询所有 salary + performance 的和
select * from sum(salart + IFNULL(performance,0)) form emp;
-- 求 salary 的评价值
select AVG(salary) from emp;
-- 求最大salary 最小salary
select MAX(salary),MIN(salary) from emp;
sql 分组查询 group by
分组查询:将查询结果按一个或多个字段进行分组,字段值相同的为一组
分组使用:
- 当 group by 单独使用时,只显示每组的第一条记录,所以,group by 单独使用意义不大
select * from emp GROUP BY gender;

SQL模糊查询,sum,AVG,MAX,min函数的更多相关文章
- 聚合函数:sum,avg,max,min,count
group by 分组的使用方法 数学函数:ABS.ceiling.floor.power.round.sqrt.square 练习:
- group by与avg(),max(),min(),sum()函数的关系
数据库表: create table pay_report( rdate varchar(8), --日期 region_id varchar(4), --地市 ...
- sql模糊查询
SQL 模糊查询 在进行数据库查询时,有完整查询和模糊查询之分. 一般模糊查询语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式: ...
- SQL 模糊查询
在进行数据库查询时,有完整查询和模糊查询之分.一般模糊查询语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式:1,%:表示任意0个 ...
- SQL 模糊查询(like)
在进行数据库查询时,有完整查询和模糊查询之分. SQL模糊查询,使用like比较字,加上SQL里的通配符,请参考以下: 1.LIKE'Mc%' 将搜索以字母 Mc 开头的所有字符串(如 McBadde ...
- [转]SQL 模糊查询
在进行数据库查询时,有完整查询和模糊查询之分. 一般模糊查询语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式: 1,% :表 ...
- 8.mybatis动态SQL模糊查询 (多参数查询,使用parameterType)
多参数查询,使用parameterType.实例: 用户User[id, name, age] 1.mysql建表并插入数据 2.Java实体类 public class User { public ...
- SQL模糊查询与删除多条语句复习
string IDlist="1,2,3"; 批量删除数据 StringBuilder strsql=new StringBuilder(); strSql.Append(&quo ...
- Jmeter中JDBC Request和BeanShell PostProcessor的结合使用(SQL模糊查询)
[前言] 今天记录一下Jmeter中JDBC Request和BeanShell PostProcessor的结合使用的方法(SQL模糊查询) [步骤] 1.下载对应数据库的驱动包到jmeter安装目 ...
随机推荐
- bzoj 4543: [POI2014]Hotel加强版
Description 给出一棵树求三元组 \((x,y,z)\,,x<y<z\) 满足三个点两两之间距离相等,求三元组的数量 Solution 考虑暴力 \(DP\) 设 \(f[i][ ...
- SpringSecurity 3.2入门(6)简单介绍默认使用的十一个过滤器
Security提供了20多个filter,每个过滤器都提供特定的功能.这些filter在Spring Security filter过滤器链中的缺省顺序由 org.springframework.s ...
- 自己用jquery+css+div写的一个弹窗
弹窗支持两种模式,一种是普通信息提示框,调用方法:popup.msgPopup(msg); 另一种是可以加载页面的弹窗,调用方法:popup.pagePopup(url); 效果图: css代码 ;; ...
- 将代码托管到github,并生成链接访问
转眼间加入github的阵营已经两年多了,看到别人建立的个人博客挺好看的,因此,自己从此喜欢上了github,总结下自己的相关知识. 推荐学习Git的网址: 猴子都能懂的GIT入门 http://ba ...
- Java Web基础——Action+Service +Dao三层的功能划分 (转载)
原文:https://blog.csdn.net/inter_peng/article/details/41021727 仅供自己学习使用: 1. Action/Service/DAO简介: Acti ...
- C#+ObjectArx CAD二次开发(2)
前面开了一个头,这里添加几个功能的实现, //添加图层 private void LoadLayer() { Document acDoc = Application.DocumentManager. ...
- PAT 1024 Palindromic Number
#include <cstdio> #include <iostream> #include <cstdlib> #include <algorithm> ...
- mysql 字符串转换呈毫秒值
SELECT CEIL((UNIX_TIMESTAMP('2011-05-31 23:59:59') - UNIX_TIMESTAMP('2011-05-31 00:59:59'))/1000/60/ ...
- angular2-模板驱动表单
app.module.ts 导入 FormsModule import { NgModule } from '@angular/core'; import { BrowserModule } fro ...
- vue loading组件
<!-- * * loadingGif组件--"数据请求中" * * 使用方法: * <loading-gif :show-loading="showLoad ...