sql 面試題 函式 求工資第n多的工資
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
select e1.Salary from
(select distinct Salary fromEmployee) e1
where
(
select count(*) from
(select distinct Salary from Employee) e2
where e2.Salary>e1.Salary)=N-1
);
END
select count(*) from
(select distinct Salary from Employee) e2
where e2.Salary>e1.Salary)
相當於 遍歷e1裡的所有的salary
然後列出e2裡大於e1中每一個salary的所有記錄
當N-1=0時 e1.salary是最大值
當N-1=1時 e1.salary是第二大值
。。。。。。
自行腦補測試
相關推薦
sql 面試題 函式 求工資第n多的工資
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN RETURN ( select e1.Salary from (select distinct Salary fromEmpl
微軟面試題:雞蛋從第N層及以上的樓層落下會摔破
題目: 有一棟樓共100層,一個雞蛋從第N層及以上的樓層落下來會摔破, 在第N層以下的樓層落下不會摔破。給你2個雞蛋,設
SQL面試題 三(單表、多表查詢)
一、給定一張學生成績表tb_grade:學號,姓名,科目號,科目名,分數。(如下表) (select * from tb_grade order by Sno,Cno;)+------+-------+-----+-------+-------+ | Sno | Sna
筆面試題之 求小於N的質數中和為N的質數對
輸入正整數N,若存在小於N的質數對(a,b),使得兩者之和為N,求這樣的質數對有多少? 這道題首先肯定是要求小於N的質數,將小於N的質數放入一個長度可變的資料結構,那麼這個資料結構中的整數們一定是有序的。 然後既然是有序的,就可以優化之讓兩個指標分別指向開頭
【面試題】求包含n個節點(從1到n,n個節點)的所有二叉搜尋樹
二叉搜尋樹滿足的條件 當前根節點的值大於左子樹節點的值 當前根節點的值小於右子樹節點的值 左右子樹同樣是二叉搜尋樹 根據上述規則可以看出,根節點值不同,形成的二叉搜尋樹就不同,那麼[1:n]範圍內的n個數就有n個不同的選擇。 [1:i−1]這i-1
【面試題】 求連結串列倒數第K個節點
題目:輸入一個連結串列輸出連結串列中的第K個節點,(計數從1開始),連結串列節點定義如下: //定義結構 struct ListNode { ListNode() :_next(NULL) ,_data(0) {} ListNode *_next; int
面試題: 求N個數中前k個大的數(大資料)
解題思路:一般思路就是將N個數排序後,取前k個數就ok。但是如果N個數是幾十億個數,載入不到記憶體怎麼辦?這就需要另外一種思路了,那就是利用堆。 具體的思路是:先建一個k個數的小堆,然後從k+1個數往
今天做的一個SQL面試題,用到了HAVING語句來限制函式關係
面試題目如上。第一題的問題主要是理解問題,容易寫成去掉"李明"的課程的學生,而不是沒選他課的學生比如錯誤sql:SELECTS.SNOFROMSLEFT JOIN SC ON S.SNO = SC.SNOWHERESC.CNO NOT IN (SELECTCNOFROMCWH
一箇中興的面試題,輸入兩個數n和m,從數列1,2,3……n中隨意取幾個數,使其和等於m,要求將其中所有組合列出來程式設計求解(c語言遞迴函式分解法)
原題目:輸入兩個數n和m,從數列1,2,3……n中隨意取幾個數,使其和等於m,要求將其中所有組合列出來程式設計求解 c語言解法分析: 先判定n和m的大小,如果m小於n,則只需從1,2……m之間找出和為m的組合即可,如果m大於n,則需要判斷1~n的和是否
【SQL】今天的一個sql面試題(分組函式使用)
已經對試題做了化名處理。 表記錄如下: 根據表記錄,利用sql得出如下的結果: 這裡之所以記錄下來,是因為這個sql必須要用到高階分析函式,就是分組內排序和分組求和。 意思就是,題目要求就是按照deptno來分組,然後在分組內將記錄按照sal來排序,並且求得每條記錄
一條SQL語句面試題:求選修所有課程的學生
前幾天求職面試,有一道SQL題:給出三個表:學生、課程、成績,求選修了所有課程的學生。一道看似很簡單的問題,把我難住了,我改了又改,塗塗畫畫,抓耳撓腮,因為試卷沒有多少空白位置了,最後只好放棄。心情大受影響,儘管最後還是獲得offer。但是心中有愧呀!於是在機器上試了試:先建
sql 面試題
試題 null cheng sel rom 姓名 缺少 學生 sid s:學生表 學生ID姓名k:課程表課程ID課程名稱 c:成績表成績ID學生ID課程ID成績1、查 各門課程中缺少考試成績的學生select a.sname,a.kname from (select *
SQL面試題-行列互換-if、【case when】
alt 技術 我們 rim case when ade 建表 行數 prim http://www.cda.cn/view/21469.html tb_lemon_grade中,表中字段id,student_name,course,score分別表示成績id,學生姓名,課
js面試題之求數組最值
pre 面試 可能 cti clas return n) ole arr 今天繼續分享js常見的面試題,求數組最大值,最小值,這裏列舉4種常見解法,還有其他方法也可以實現,讀者知道可以私信我,我將把意見列舉到博客中,歡迎提出意見。 第一種,利用數組排序 1 var arr
SQL面試題
and 試題 mit heat 指定 查詢 刪除 關聯 ner 1.表結構-- Create table 課程表 create table T_COURSE ( cno VARCHAR2(20), cname VARCHAR2(20),
java算法面試題:有數組a[n],用java代碼將數組元素順序顛倒
mage post alt 數組a array [] ima log 算法 package com.swift; import java.util.ArrayList; import java.util.Collections; import java.util.Lis
必看,經典sql面試題(學生表_課程表_成績表_教師表)
tin bsp get upload png idt cimage gem 公開 點擊鏈接加入QQ群 522720170(免費公開課、視頻應有盡有):https://jq.qq.com/?_wv=1027&k=5C08ATe http://xqtesting.com
經典的一套SQL面試題及答案
SQL SqlServer 數據庫 面試經典的一套SQL面試題及答案
面試題11-求數值的整數次方
import str 整數 面試 1.0 pre pow col 類型 題目描述 給定一個double類型的浮點數base和int類型的整數exponent。求base的exponent次方。 代碼 import java.lang.Math; public cl
經典Sql面試題收集!!
Sql常見面試題(總結) 1.用一條SQL語句 查詢出每門課都大於80分的學生姓名 name kecheng fenshu 張三 語文 &nb