當前位置:首頁 » 編程語言 » 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