Sql语句你知道多少(七)------select语句

来源:互联网 发布:矩阵列向量线性无关 编辑:程序博客网 时间:2024/04/30 02:51

使用And和Or运算符

1.使用And进行查询

select *from tb_Student where english>80 and chinese>90

and查询要求返回的结果必须同时满足两个表达式

2.利用or进行查询

select *from tb_Student where english>80 or chinese>90

or查询要求返回的结果必须同时满足两个表达式其中之一

3.同时使用And、or

注意:

当一个查询语句中同时有or和and时,and的优先级要高,先执行and

例如

select *from tb_Student where english>80 and chinese>90 or math>70和

select *from tb_Student where english>80 and (chinese>90 or math>70)所表示是不一样的。

建议在使用是用()来代替使用

数据分组统计

在数据分组统计中,要用到group by与聚合函数结合的方式

group by语法

[GROUP BY[All]expression][WITH{cube|ROLLUP}]

All:选定列表中匹配的所有组合的结果集,对不满足条件的汇总返回空值

expression:对查询执行分组的表达式

CUBE:该参数指定对于查询的结果集不仅不含Group by提供的正常行,还要包含汇总行,返回每一个可能的组和子组合的

会总行

select name,sex,sum(english) group by name,sex with bute;

RollUp:该参数指定对于查询的结果集不仅不含Group by提供的正常行,还要包含汇总行。按层次结构顺序,从组内的最低级别向最高级别

select name,sex,sum(english) group by name,sex with Rollup;

汇总

select ISBN ,name ,sum(Sellout) from tb_SellBook group by ISBN,name,SellOut order by 3 desc;

 

 

 

原创粉丝点击