皎皎空中孤月轮,超级灵气无弹窗,夏天是谁演的
聚合函数 count,max,min,avg,sum...
select count (*) from t_employee
select max(fsalary) from t_employee
排序 asc升序 desc降序
select * from t_employee order by fage
先按年龄降序排列。如果年龄相同,则按薪水升序排列
select * from t_employee order by fage desc,fsalary asc
order by 要放在 where 子句之后
通配符过滤
通配符过滤用like
单字符通配符‘_'
多字符通配符‘%'
select * from t_employee where fname like '_erry'
null 是不知道的意思,而不是没有
用sql语句查询null的数据不能用=或<> 而用is null或者is not null
select * from t_employee where fname is null
in(23,25)同时匹配两个值。相当于 23 or 25
between 20 and 30 匹配介于20到30之间的数
group by分组
select fage, count(*) from t_employee
group by fage
先把相同的fage分一组,再统计每一组的个数
group by子句要放在where子句之后。如果想取某个年龄段人数大于1的,不能用where count(*) > 1 ,因为聚合函数不能放在where子句之后。要用having子句
having是对分组后的列进行过滤,能用的列和select中的一样。如下例中则不能用having fsalary>2000 只能用where fsalary>2000
select fage, count(*) from t_employee
group by fage
having count(*) > 1;
限制结果集的范围
select top 3 * from t_employee
order by fsalary desc
从第六名开始选3个.2005后可以用row_number函数
select top 3 * from t_employee
where fnumber not in(select top 5 fnumber from t_employee order by fsalary desc)
order by fsalary desc
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
-
网友评论