单表数据记录查询
2016-06-24 09:13
169 查看
一、DISTINCT的用法(查询多个字段,仅对其中一个去重复)
distinct必须放在开头
正确写法
二、实现数学四则运算数据库查询(+-*/%)
三、函数CONCAT()来连接字符串
四、BETWEEN AND(NOT BETWEEN AND)
五。IS NULL(IS NOT NULL)
带IS NULL 关键字的空值查询
六、IN ( NOT IN )
注:由于NULL不能进行如何的“操作”
–如果null参与算术运算,则该算术表达式的值为null。(例如:+,-,*,/ 加减乘除)
–如果null参与比较运算,则结果可视为false。(例如:>=,<=,<> 大于,小于,不等于)
–如果null参与聚集运算,则聚集函数都置为null。除count(*)之外。
–如果在not in子查询中有null值的时候,则不会返回数据。
七、Like
“_”通配符:能匹配单个字符
“%”通配符:能匹配任意长度,既可以是0个又可以是一个,还可以是N个
八、ORDER BY
九、LIMIT(常用于分页)
MySql所支持的统计函数,如果所操作的表中没有任何数据记录, count函数返回数据为NULL 其余返回为0
十、COUNT
十一、AVG统计平均值
SUM求和
MAX、MIN最大最小值
十二、GROUP BY
十三、GROUP_CONCAT
十四、
十五、
十二、
十二、
十二、
distinct必须放在开头
错: select id, distinct name from table
正确写法
select *, COUNT(DISTINCT Sno ) from student_course GROUP BY Sno
二、实现数学四则运算数据库查询(+-*/%)
select ename,moonSalay*12 as yearSalary from t_employee;
三、函数CONCAT()来连接字符串
//Mary的年薪为:800000.00 select concat(ename,‘雇员的年薪为:’,moonSalary*12 ) yearSalary from employee;
四、BETWEEN AND(NOT BETWEEN AND)
//包含边界 select * FROM student_course where student_course.grade BETWEEN 50 and 80
五。IS NULL(IS NOT NULL)
带IS NULL 关键字的空值查询
select * from student where grade IS not null
六、IN ( NOT IN )
select * from student where stuNum In (10,21,56,54,89)
注:由于NULL不能进行如何的“操作”
–如果null参与算术运算,则该算术表达式的值为null。(例如:+,-,*,/ 加减乘除)
–如果null参与比较运算,则结果可视为false。(例如:>=,<=,<> 大于,小于,不等于)
–如果null参与聚集运算,则聚集函数都置为null。除count(*)之外。
–如果在not in子查询中有null值的时候,则不会返回数据。
--正确写法 SELECT * FROM dbo.Table_A AS a WHERE a.ID NOT IN ( SELECT b.ID FROM dbo.Table_B AS b WHERE b.ID IS NOT NULL ) --排除NULL值参与运算符比较
七、Like
“_”通配符:能匹配单个字符
“%”通配符:能匹配任意长度,既可以是0个又可以是一个,还可以是N个
select * from student where name Like 'A%' select * from student where name Like 'a%' //查询结果一样,不区分大小写 select * from student where NOT name Like 'A%' select * from student where name Like '_A%' //查询所有数据记录 select* from student where name like '%%'
八、ORDER BY
//单字段升序(默认)排列 select * from student order by grade //单字段降序排列 select * from student order by grade desc //多字段排序 select * from student order by grade,date desc
九、LIMIT(常用于分页)
select * from student LIMIT(a,b) //a为起始位置,B表示查询的条数 select * from student LIMIT b //不指定起始位置则从第一条开始
MySql所支持的统计函数,如果所操作的表中没有任何数据记录, count函数返回数据为NULL 其余返回为0
十、COUNT
//统计所有数据记录的条数,不管是不是NULL select count(*) allNumber from student //NULL的不统计 select count(course) partNumber from student
十一、AVG统计平均值
SUM求和
MAX、MIN最大最小值
十二、GROUP BY
// select * from student group by stuClass
十三、GROUP_CONCAT
十四、
十五、
十二、
十二、
十二、
相关文章推荐
- android中炫酷的界面设计以及下拉刷新效果
- linux 下 eclipse 开发环境的搭建
- [转载]Eclipse.ini的相关说明
- Hibernate 的原生 SQL 查询
- URL地址最大长度
- php scandir函数,print_r函数的问题
- iOS开发拓展篇—音频处理(音乐播放器5)
- 机器学习之(四)特征工程以及特征选择的工程方法
- Docker 深感 Mesos、Kubernetes 威胁,Engine 中内置编排
- Selenium 2.0自动化测试
- 构建之法阅读笔记5
- PHP微信开发之模板消息回复
- 从vSphere 5.5升级到6之2-升级vCenter Server 5.5到6.0
- MySQL& SQL Server&Microsoft Access数据类型一览
- 中国天气预报数据API收集
- [李景山php]每天laravel-20160907|Dispatcher-7
- 关于C++编译的程序无法在新一台电脑上运行总结
- 如何改变状态栏文字和背景颜色
- C# 讲解五种导出access数据到Excel文件格式中
- [李景山php]每天laravel-20160907|Dispatcher-7