1.
select * from employees order by hire_date desc limit 1;
2.
select * from employees order by hire_date desc limit 2,1;
3.
select a.*,b.dept_no from salaries as a inner join dept_manager as b on a.emp_no=b.emp_no where a.to_date='9999-01-01' and
b.to_date='9999-01-01' order by emp_no;
//此題虐寤螅客代碼編輯器一直報(bào)錯(cuò)龙致,不明原因
4.
select b.last_name,b.first_name,a.dept_no from dept_emp as a inner join employees as b on a.emp_no=b.emp_no;
5.
select b.last_name,b.first_name,a.dept_no from employees as b left join dept_emp as a on a.emp_no=b.emp_no;
6.
select a.emp_no,b.salary from employees as a inner join salaries as b
on a.emp_no=b.emp_no and a.hire_date=b.from_date
order by a.emp_no desc;
// sql 語(yǔ)句其實(shí)有很多寫(xiě)法 绩脆,可以只針對(duì) b 分組查詢掰茶。我傾向使用join.
SELECT
emp_no,
salary
FROM
salaries
GROUP BY
emp_no
HAVING
min( from_date )
ORDER BY
emp_no DESC
7.
select emp_no,count(*) as t from salaries group by emp_no having t>15;
8.
select distinct salary from salaries where to_date='9999-01-01' order by salary desc
9.
select b.dept_no,b.emp_no,a.salary from salaries as a left join dept_manager as b on a.emp_no=b.emp_no
where a.to_date='9999-01-01' and b.to_date='9999-01-01';
10.
select a.emp_no from employees as a left join dept_manager as b on a.emp_no=b.emp_no where b.emp_no is null;
11.
select a.emp_no,b.emp_no as manager_no from dept_emp as a left join dept_manager as b
on b.dept_no=a.dept_no where a.emp_no!=b.emp_no and b.to_date='9999-01-01';
// 題目限制條件太多暇藏, 容易看漏
12.
不會(huì)!濒蒋!
MySQL 報(bào)錯(cuò)的答案能通過(guò)所有測(cè)試用例 盐碱, 服氣把兔!
13.
select title,count(*) as t from titles group by title having t >= 2;
14.
select title,count(*) as t from
(select distinct emp_no,title from titles)
group by title having t >= 2;
15.
select * from employees where (emp_no%2)==1 and last_name!='Mary' order by hire_date desc;
16.
select a.title, avg(b.salary) as avg
from salaries as b inner join titles as a
on a.emp_no=b.emp_no
where b.to_date='9999-01-01' and a.to_date='9999-01-01'
group by a.title;
17.
select emp_no,salary from salaries where to_date='9999-01-01' order by salary desc limit 1,1
18.
select a.emp_no, b.salary, a.last_name, a.first_name
from employees as a inner join salaries as b on a.emp_no=b.emp_no
where b.to_date='9999-01-01'
and b.salary = (select max(s.salary) from salaries as s where s.salary < (select max(salary) from salaries) )
19.
select a.last_name,a.first_name,b.dept_name
from employees as a left join
(select c.emp_no,c.dept_no,d.dept_name from dept_emp as c left join departments as d
on c.dept_no=d.dept_no) as b
on a.emp_no=b.emp_no;
20.
select Max(salary)-Min(salary) as growth from salaries where emp_no=10001 group by emp_no
SQL 實(shí)戰(zhàn) 糯炷穑客網(wǎng) 20/61題
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)贮配,“玉大人谍倦,你說(shuō)我怎么就攤上這事±崂眨” “怎么了昼蛀?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)圆存。 經(jīng)常有香客問(wèn)我叼旋,道長(zhǎng),這世上最難降的妖魔是什么辽剧? 我笑而不...
- 正文 為了忘掉前任送淆,我火速辦了婚禮,結(jié)果婚禮上怕轿,老公的妹妹穿的比我還像新娘偷崩。我一直安慰自己,他們只是感情好撞羽,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布阐斜。 她就那樣靜靜地躺著,像睡著了一般诀紊。 火紅的嫁衣襯著肌膚如雪谒出。 梳的紋絲不亂的頭發(fā)上,一...
- 那天邻奠,我揣著相機(jī)與錄音笤喳,去河邊找鬼。 笑死碌宴,一個(gè)胖子當(dāng)著我的面吹牛杀狡,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播贰镣,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼呜象,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼膳凝!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起恭陡,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤蹬音,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后休玩,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體著淆,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年哥捕,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了牧抽。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站愧薛,受9級(jí)特大地震影響晨炕,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜毫炉,卻給世界環(huán)境...
- 文/蒙蒙 一瓮栗、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧瞄勾,春花似錦费奸、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至趾疚,卻和暖如春缨历,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背糙麦。 一陣腳步聲響...
- 正文 我出身青樓魄缚,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親仆邓。 傳聞我的和親對(duì)象是個(gè)殘疾皇子鲜滩,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 57.使用含有關(guān)鍵字exists查找未分配具體部門(mén)的員工的所有信息 58.獲取employees中的行數(shù)據(jù),且這些...
- 1、前言 結(jié)構(gòu)化查詢語(yǔ)言(Structured Query Language)簡(jiǎn)稱SQL幢炸,是一種特殊目的的編程語(yǔ)言...
- 25.獲取員工其當(dāng)前的薪水比其manager當(dāng)前薪水還高的相關(guān)信息 題目描述:獲取員工其當(dāng)前的薪水比其manage...
- 33.創(chuàng)建一個(gè)actor表库物,包含如下信息 34.批量插入數(shù)據(jù) 35.批量插入數(shù)據(jù),不使用replace操作 36....
- 41.構(gòu)造一個(gè)觸發(fā)器audit_log 42.刪除emp_no重復(fù)的記錄诲侮,只保留最小的id對(duì)應(yīng)的記錄 43.將所有...