查询表信息
desc tableName
查看用户
Show user
清理屏幕
host cls
分组函数:
avg 平均
sum 累加
min 最小值
max 最大值
count 计数
wm_concat 行转列
非空过滤
nvl
例:count(nvl(name,0))
注意:
count(*) 计数时未过滤了非空值
count(name) 计数时过滤了非空值
注意:
1.在select列表中所有未包含在组函数中的列都应该包含在group by子句中
2.包含在group by子句中的列不必包含在select列表中
Where & Having的区别
selece name,avg(sal) from table
group by name
having avg(sal) > 2000
where不能使用分组函数
注意:从sql优化的角度上看,尽量使用where
Group by 增强
select name1,name2,sum(sal) from table group by name1,name2;
+
select name1,sum(sal) from table group by name1;
+
select sum(sal) from table;
等于
select name1,name2,sum(sal) from table group by rollup( name1,name2);
设置展示格式
set linesize 200
set pagesize 30
col name for a60
break on name skip 2