Update语句
Update 表名 set 字段1=值1, 字段2=值2 where 条件
练习:
把用户名带 ‘小’的人的密码设置为123456@
语句:UPDATE crm_user SET userpwd='123456@' WHERE username LIKE '%小%';
效果
Group by 、having: 分组查询 having分组查询条件
语法:SELECT A ,COUNT(B) FROM TABLE GROUP BY A HAVING COUNT(B)>2
Mysql内置统计函数
Count(列名) 总计
Sum(列名) 求和
Avg(列名) 平均
Max(列名) 最大值
Min(列名) 最小值
举例:
1.求班级的平均分数
SELECT class,scores, AVG(scores) FROM jian_scores GROUP BY class;
2.求班级的平均分数,并且要求分数高于70分
SELECT class,scores, AVG(scores) FROM jian_scores GROUP BY class HAVING AVG(scores)>70;
联合查询:
查询jian_scores的id=1,jian_hometown的cityid=5
SELECT jian_scores.id,jian_scores.students,jian_hometown.city FROM jian_scores,jian_hometown WHERE jian_scores.id='' AND jian_hometown.cityid=''