一道sql面試題,題目很簡單。
年份 工資
----------- -----------
2000 1000
2001 2000
2002 3000
2003 4000
這裡有乙份公司表,一句sql查詢出下列結果
年份 工資
----------- -----------
2000 1000
2001 3000
2002 6000
2003 10000
--author:【dba】小七set nocount on
declare @t table (年份 int ,工資 int)
insert into @t
select 2000,1000 union all
select 2001,2000 union all
select 2002,3000 union all
select 2003,4000
select * from @t
select a.年份, sum(b.工資) as 工資 from @t a,@t b where a.年份》=b.年份 group by a.年份
select 年份, (select sum(工資) from @t where 年份 <= a.年份) 工資 from @t a --m提供的另外乙個寫法,呵呵
set nocount off
年份 工資
----------- -----------
2000 1000
2001 2000
2002 3000
2003 4000
年份 工資
----------- -----------
2000 1000
2001 3000
2002 6000
2003 10000
sql 分組統計 面試題
兩道sql面試題,那人把試卷給我後居然坐在對面盯著看,我承認我受不了這個,愣死沒答出來。他很鄙視我物件導向的四大特性只聽說過三個,汗 回來後幾分鐘搞定,不一定是最好的,但能應付筆試題。1.表test結構 group score a 勝 b 負 a 負 b 勝 檢索結果 組 勝 負 a 1 1 b 1...
報表統計 sql面試題
有3張表 學生表 s 字段 學生編號 學生姓名 課程表 c 字段 課程編號 課程名稱 成績表 sc 字段 學生編號 課程編號 分數 需要實現最終效果如下 後面有些課程省略沒有截圖了 實現的方法 方法一 select max s.name as姓名,max case when sc.cid 1 the...
報表統計 sql面試題
有3張表 學生表 s 字段 學生編號 學生姓名 課程表 c 字段 課程編號 課程名稱 成績表 sc 字段 學生編號 課程編號 分數 需要實現最終效果如下 後面有些課程省略沒有截圖了 實現的方法 方法一 select max s.name as姓名,max case when sc.cid 1 the...