您的位置:首页 > 数据库

有关数据库的一些基本知识

2015-08-01 19:20 429 查看

新建数据库表

create table employee(
eid int(15) primary key auto_increment,
ename varchar(20) not null,
salary float(9,2) not null,
deptid int(15) not null
);


1、用两种方式根据部门号从高到低,工资从低到高列出每个员工的信息

select * from employee order by deptid desc,salary;




2、列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序

首先,下面这条语句是查询各个部门的平均工资

select avg(salary) from employee group by deptid;




order by 与 group by 的区别:

order by 是排序;group by 是分组。 具体区别,再写个例子,一看便知:

select * from employee group by deptid desc,salary;




select * from employee group by deptid desc;




#

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: