你这句话说得本来就有毛病我想在员工表(emp)中查询部门(dep)平均工资大于1200,的员工编号,员工所在部门和此部门中有多少工资(salary)大于1200的!平均工资大于1200 那当然结果是某个部门了 如果要 员工编号 那就是该 部门所有的 员工编号后面又说此部门中有多少工资(salary)大于1200的!
那只能是该部门的部分员工了--平均工资大于1200的所有部门的
select emp_id , dep
from emp
where dep in(select dep from emp group by (dep) having avg(salary) > 1200)
--工资(salary)大于1200的
select emp_id , dep
from emp
where dep in(select dep from emp group by (dep) having avg(salary) > 1200)
and salary > 1200
那只能是该部门的部分员工了--平均工资大于1200的所有部门的
select emp_id , dep
from emp
where dep in(select dep from emp group by (dep) having avg(salary) > 1200)
--工资(salary)大于1200的
select emp_id , dep
from emp
where dep in(select dep from emp group by (dep) having avg(salary) > 1200)
and salary > 1200
解决方案 »
- 地区搜索问题
- 插入10万条记录要多久,用MS
- 将表数据生成SQL脚本的存储过程,网上很多,但不知道怎么使用?!
- 一个查询,请前辈指点一下,我郁闷很久了!!
- A字段默认值=B字段*1.5怎么做啊?
- 很简单一问update table where....
- 请问这样的SQL语句怎样写?
- 请帮忙写一个存储过程!
- DTS的文本到文本能否加限制只取满足条件的行?
- 菜鸟问题!sql server 2000中为什么关于group by的语句老是有错误信息啊!
- 进行sum()操作,用不用必须进行isnull()判断呢?
- 谁能给我讲讲[B]=sum(case when score='B' then 1 else 0 end),这句是什么意思?
猜想:表结构:员工表(emp): 员工号(pid) 所在部门(dep) 工资(salary)一、员工所在部门和此部门中有多少工资(salary)大于1200的!select 部门=dep,
数量=(select count(1) from emp where dep=a.dep)
from emp a group by dep二、查询部门(dep)平均工资大于1200,的员工编号那么表结构中必须有个时间字段,表示在哪个时间内的工资为多少