创建表,班级,属性年级,班级号
create table class(
id number primary key ,
grade varchar2(6),
class_no number
);
删除表
drop table class;
删除一条
delete from mytable where id= 1 ;
插入全部和部分
insert into class values(1,'高一',01);
insert into class(id,grade) values(2,'高二');
查询空字段
select *from class where class_no is null ;
左外连接
select * from student s
left join class c on s.class_id=c.id
where ...and...
分组
1.常用的分组函数:AVG平均值,SUM求和,MIN最小值,MAX最大值,COUNT个数,WM_CONCAT字符串的拼接等。
2.group by 分组查询,select子句后的任一非聚合函数字段都应来源于group by 分组语句后,否则语法会编译不通过。
3.order by是具体条件
select sex,MAX(age) from student group by sex;
查多个分组字段
select name,age from student
group by age,name
order by age;
where+group by+having
SELECT SNAME,SAGE FROM STUDENT
where SSEX='男'
GROUP BY SNAME,SAGE
HAVING SAGE>'21'
网友评论