当前位置:首页 » 编程语言 » sql查员工工资
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql查员工工资

发布时间: 2023-01-15 10:03:44

sql 查询每个员工不同年份的工资比较情况

declare @A table(ID int,Salary int,TimeD varchar(30))
insert into @A select 1, 100, '2008-01-01 00:00:00'
insert into @A select 1, 100, '2008-02-01 00:00:00'
insert into @A select 1, 100, '2008-03-01 00:00:00'
insert into @A select 1, 100, '2008-04-01 00:00:00'
insert into @A select 2, 200, '2008-01-01 00:00:00'
insert into @A select 2, 200, '2008-02-01 00:00:00'
insert into @A select 2, 200, '2008-03-01 00:00:00'
insert into @A select 2, 200, '2008-04-01 00:00:00'
insert into @A select 1, 100, '2009-01-01 00:00:00'
insert into @A select 1, 100, '2009-02-01 00:00:00'
insert into @A select 1, 100, '2009-03-01 00:00:00'
insert into @A select 1, 100, '2009-04-01 00:00:00'
insert into @A select 2, 200, '2009-01-01 00:00:00'
insert into @A select 2, 200, '2009-02-01 00:00:00'
insert into @A select 2, 200, '2009-03-01 00:00:00'
insert into @A select 2, 200, '2009-04-01 00:00:00'
insert into @A select 1, 120, '2010-01-01 00:00:00'
insert into @A select 1, 120, '2010-02-01 00:00:00'
insert into @A select 1, 120, '2010-03-01 00:00:00'
insert into @A select 1, 120, '2010-04-01 00:00:00'
insert into @A select 2, 220, '2010-01-01 00:00:00'
insert into @A select 2, 220, '2010-02-01 00:00:00'
insert into @A select 2, 220, '2010-03-01 00:00:00'
insert into @A select 2, 220, '2010-04-01 00:00:00'
select *
from(
select ID,sum(Salary) as SaylarTotal,CAST(Year(TimeD) AS CHAR(4)) as DateYear from @A group by ID,Year(TimeD)
) PQ
PIVOT
(Sum(SaylarTotal) for DateYear IN ([2008],[2009],[2010])
) AS PVT

执行结果是:
ID 2008 2009 2010
1 400 400 480
2 800 800 880

之前可预设
EXEC sp_dbcmptlevel '数据库名', 90

㈡ 如何用t-sql语句查询职工的姓名、工资及所在城市信息,条件是:工资在5000~10000,并且城市在广州

你好,不同的表结构查询语句是不一样的,有的表结构需要按多表联合查询,有的单表查询即可。请提供表结构,大家好帮助你。

㈢ 用SQL语句怎么查询最高工资和最低工资的人

1、首先查出最低工资和最高工资,要考虑到并列最高和最低的情况
2、使用最高工资和最低工资作为条件关联工资表,获得人的ID
3、使用人的ID关联用户表,查出人的信息

㈣ 编写一个 SQL 查询,找出每个部门工资前三高的员工

Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 department Id 。

+----+-------+--------+--------------+
| Id | Name | Salary | DepartmentId |
+----+-------+--------+--------------+
| 1 | Joe | 70000 | 1 |
| 2 | Henry | 80000 | 2 |
| 3 | Sam | 60000 | 2 |
| 4 | Max | 90000 | 1 |
| 5 | Janet | 69000 | 1 |
| 6 | Randy | 85000 | 1 |
+----+-------+--------+--------------+
Department 表包含公司所有部门的信息。

+----+----------+
| Id | Name |
+----+----------+
| 1 | IT |
| 2 | Sales |
+----+----------+
编写一个 SQL 查询,找出每个部门工资前三高的员工。例如,根据上述给定的表格,查询结果应返回:

+------------+----------+--------+
| Department | Employee | Salary |
+------------+----------+--------+
| IT | Max | 90000 |
| IT | Randy | 85000 |
| IT | Joe | 70000 |
| Sales | Henry | 80000 |
| Sales | Sam | 60000 |
+------------+----------+--------+

Sql如下:
SELECT
d.Name Department,e1.Name Employee,e1.Salary Salary
FROM
Employee e1,
Employee e2 ,
Department d
WHERE
e1.DepartmentId = e2.DepartmentId
AND e1.Salary <= e2.Salary
and e1.DepartmentId=d.Id
group by e1.id
having count(DISTINCT e2.Salary)<=3
order by d.Name,e1.Salary desc

㈤ 如何用SQL语言实现计算人员工资总额及人员人数

计算工资总额:
这是查询:sql=“selest
sum(工资)
as
总共工资
from
工资表”
这是显示:rs(“总共工资”)
计算员工总数:
这是查询:sql=“selest
count(员工姓名)
as
总员工数
from
员工“
显示同上:rs(”总员工数“)
注:以上语句中的”总工资数“”总员工数“为自定义字段,数据表中没有
只是临时建立的一个字段
追分的话你看着给
golongfly
你没用AS转换
怎么显示出来啊?

㈥ 用SQL语句怎样查年薪和月薪

这个问题,首先要有个思路:
1 求年薪和月薪,那么首先要确定,年薪和月薪是怎么算的,
根据你的描述,发薪水没有固定日期,比如说这个月发了4次薪水,那么这个人的这个月的月薪水就是这四次的钱加起来,这样算的话,月薪就是每个月单独计算特有的,但是你说的这个月薪是年平均的还是按月单独算呢?
假设是年平均的吧:
select t1.staff_name, sum(t1.staff_salary)/12 as 月薪 from salary t1
where t1.salary_date>to_date('2010-01-01','YYYY-MM_DD')
and t1.salary_date<to_date('2010-12-31','YYYY-MM_DD')
group by t1.staff_name

年薪:
select t1.staff_name, sum(t1.staff_salary) as 年薪 from salary t1
where t1.salary_date>to_date('2010-01-01','YYYY-MM_DD')
and t1.salary_date<to_date('2010-12-31','YYYY-MM_DD')
group by t1.staff_name

月薪在500-800之间的员工姓名,这个不用我写了吧。
当然,单独算月薪也是可以的,需要的话给我留言~

㈦ 一条sql语句查询每个员工的工资都大于5000的部门

1、select * from 部门

2、where not exists (select * from 员工 where 员工.部门号=部门.部门号 and 工资 <= 5000)

㈧ sql查询员工的基本工资排名第3-6位的姓名和基本工资

sql查询员工的基本工资排名第3-6位的姓名和基本工资
select top 4 姓名,工资 from 表a where 姓名 not in (select top 2 姓名 from 表a order by 工资 desc) order by 工资 desc

㈨ sql查询所有男员工在2014-1-28的工资信息要求输出员工姓名及所以工资信息

select 姓名,员工编号,基本工资,社保公积金,奖金
from 员工表
where 性别=‘男’ and 日期=‘2014-01-28’

㈩ SQL查询最高工资的员工,求原因~

我们一般都会这样写:
select name from table where salary = (select max(salary) from table);
答: select max(salary) from table 这句话就是取出公司所有人员的最大工资
然后抓出最高工资的人员是谁,也就是题目所要求的答案

为什么不能这样写?
select name,max(salary) from table;

答: 这句话是抓出员工所拿到的最高薪资是多少,比如一个员工可能每个月拿的工资不一样
而你这句话就是抓这个员工拿得最高时候的薪资是多少,只是针对这个员工
而题目的要求是要抓所有员工中拿到最高薪资的人员.

不知道是不是明白.呵呵
用数据举例
name salary
A 3000
B 4000
B 5000
A 2000

select max(salary) from table ----是取出最高薪资,得到的结果是5000
select name,max(salary) from table----这是取出每个员工最高工资拿多少,得到的结果如下
A 3000
B 5000