码迷,mamicode.com
首页 > 其他好文 > 详细

10.11查询

时间:2015-10-11 16:29:41      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

select *from score--查询所有,一条条数据筛选判定select映射

--查询先后顺序 
--from,on,join(和on是用在表的连接中用),where,group by ,with cube or with rollup(一般不用), having,select,distinct,order by,top

--top 筛选前多少条 紧跟select使用,后面加数字
--like模糊查询,有三种情况,%表示通配符,表示任何具有0或者多个字元的字串,- 表示任何单一 字元
--[]表示指定范围([0-9],[a-f][A-F])或集合([sklytghtj])中的任何单一字元,[^ 1-9  ]不包含这个范围的或者集合的数据
select top 2 *from score--top查询前两条
select *from course  where cname like%导论% --模糊查询 ,$表示 含任何字符
select *from course  where cname like%导论--以导论结尾  
select *from course  where cname like导论%--以导论开头
select *from course  where cname like计算机__

--distinct去重,去处重复的数据在映射出来
select distinct cno from course 

--order by,排序asc升序,desc 降序
select * from score order by degree asc--升序,由低到高
select * from score order by degree desc--降序,由高到低
select top 1 * from score order by degree asc--升序,由低到高


--比较运算符  >,<,>=,<=,!=
--逻辑运算符and or

--聚合函数 
--一组数据计算返回一个数值,不允许和返回一列的查询不能同时用
-- min max ,avg sum,count只能聚合函数之间使用
select MAX(degree)from score 
select MAX(degree),cno from score --是错误的

select MIN(degree), max(degree),SUM(degree) from score--对的
--group by 按照..列践行分组对相同的内容进行分组 ,只能显示查询列的的数据,或最小值,或最大值,其他列不能显示 聚合函数经常与 SELECT 语句的 GROUP BY 子句一起使用。
--having筛选  只能跟在group by 后面使用,可进行再次筛选 count计算的是行数用*表示就好
select sno, min(degree) from score group by sno
select count(*)from score 

select cno from score group by cno having COUNT(*)>3 --cno 列中含相同内容多于3的映射出来
select*from score

 

10.11查询

标签:

原文地址:http://www.cnblogs.com/cf924823/p/4869399.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!