2018-09-29

交換工資.png

代碼:
update salary set=(case when sex='f' then 'm' else 'f' end);

第二高的薪水.png

select Max(t.Salary) SecondHighestSalary from Employee t where t.Salary<(select Max(b.Salary) from Employee b);

上升的溫度.png

select W1.id from Weather W1,Weather W2 where W1.Temperature>W2.Temperature
and TO_DAYS(W1.RecordDate)=TO_DAYS(W2.RecordDate)+1

分?jǐn)?shù)排序.png

select t.Score,(select count(distinct t2.Score) from Scores t2 where t2.Score>=t.Score) Rank
from Scores t order by Score desc;

第n高的薪水.png

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET N=N-1;
RETURN (
# Write your MySQL query statement below.
select distinct Salary from Employee order by Salary desc limit N,1
);
END select distinct Salary from Employee order by Salary desc limit N,1
);
END

換座位.png

select (case
when mod(id,2)!=0 and id!=counts then id+1
when mod(id,2)!=0 and id=counts then id
else id-1 end
) id,student
from seat,(select count(*) counts from seat) seat_counts
order by id asc

體育館的人流量.png

select distinct t1.*
from stadium t1,stadium t2,stadium t3
where t1.people>=100 and t2.people>=100 and t3.people>=100
and ((t1.id+1=t2.id and t2.id+1=t3.id and t1.id+2=t3.id )
or (t2.id+1=t3.id and t3.id+1=t1.id and t2.id+2=t1.id)
or(t3.id+1=t1.id and t1.id+1=t2.id and t3.id+2=t2.id))
order by t1.id

部門(mén)工資最高的員工.png

select t2.Name Department, t1.Name Employee, t1.Salary
from Employee t1, Department t2
where t1.DepartmentId = t2.Id
and t1.Salary in (select max(Salary)
from Employee, Department
where Employee.DepartmentId = Department.id
group by Employee.DepartmentId)
order by t2.id

刪除重復(fù)的郵箱.png

select * from Person t1 where t1.id not in(
select min(id) id from person group by Email)

從不訂購(gòu)的用戶.png

select t1.name Customers
from Customers t1
where t1.id not in (select CustomerId id from Orders)

連續(xù)出現(xiàn)的數(shù).png

SELECT DISTINCT l1.Num FROM Logs l1, Logs l2, Logs l3
WHERE l1.Id = l2.Id - 1 AND l2.Id = l3.Id - 1
AND l1.Num = l2.Num AND l2.Num = l3.Num;

組合兩個(gè)表.png

select FirstName, LastName, City, State from Person t1 left join Address t2 on t1.PersonId=t2.PersonId

超過(guò)5名學(xué)生的課.png

select distinct t.class from courses t group by t.class having count(distinct t.student)>=5

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容