1.SQL语句查询!!!!!!!!!!!
列出各个部门中工资高于本部门的平均工资的员工,
创建表:
mysql> create table employee921(id int primary key auto_increment,name varchar(5
0),salary bigint,deptid int);
插入实验数据:
mysql> insert into employee921 values(null,‘zs’,1000,1),(null,‘ls’,1100,1),(null
,‘ww’,1100,1),(null,‘zl’,900,1) ,(null,‘zl’,1000,2), (null,‘zl’,900,2) ,(null,‘z
l’,1000,2) , (null,‘zl’,1100,2);
答案如下
SELECT e.name,e.deptid from employee e,
(SELECT deptid,avg(salary) as asa1 from employee GROUP BY deptid) e1
where e.deptid=e1.deptid and e.salary > e1.asa1
如果要查询人数 只需要在显示中 添加 count(1)
SELECT count(1),e.name,e.deptid from employee e,
(SELECT deptid,avg(salary) as asa1 from employee GROUP BY deptid) e1
where e.deptid=e1.deptid and e.salary > e1.asa1
转发和重定向的区别:
转发服务器只进行一次请求,在服务器内部进行转发,不会丢失数据
request。getrequestDispatcher()。forward(requset,response);
重定向服务器进行两次请求,会丢失数据
response。sendRedirect();
常用内置对象
out 用来向页面中输出内容
request 客户端向服务器发送的所有请求信息
response 服务器端向客户端响应的所有信息
session 客户端和服务器的一个会话 只要浏览器不关闭 或者超过固定时间不操作就不会注销
不常用 config page pagecontext application exception
getP 和get A p是request自带的P A是我们设置是有对应的set方法