首页 > 数据库技术 > 详细

MySQL学习笔记(二)

时间:2018-01-18 15:57:49      阅读:154      评论:0      收藏:0      [点我收藏+]

转载:http://www.cnblogs.com/best/p/6517755.html

1.表达式与条件查询

 

技术分享图片

where 关键词用于指定查询条件, 用法形式为: select 列名称 from 表名称 where 条件;

以查询所有性别为女的信息为例, 输入查询语句: select * from students where sex="女";

where 子句不仅仅支持 "where 列名 = 值" 这种名等于值的查询形式, 对一般的比较运算的运算符都是支持的, 例如 =、>、<、>=、<、!= 以及一些扩展运算符 is [not] null、in、like 等等。 还可以对查询条件使用 or 和 and 进行组合查询, 以后还会学到更加高级的条件查询方式, 这里不再多做介绍。

示例:

查询年龄在21岁以上的所有人信息: select * from students where age > 21;

查询名字中带有 "王" 字的所有人信息: select * from students where name like "%王%";

查询id小于5且年龄大于20的所有人信息: select * from students where id<5 and age>20;

 

2.聚合函数

 

技术分享图片

 

获得学生总人数:select count(*) from students

获得学生平均分:select avg(mark) from students

获得最高成绩:select max(mark) from students

获得最低成绩:select min(mark) from students

获得学生总成绩:select sum(mark) from students

MySQL学习笔记(二)

原文:https://www.cnblogs.com/chechen/p/8310256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!