-- 按姓名分取最大值
select * from jobs a where exists(select 1 from jobs b where a.job_desc=b.job_desc and b.min_lvl<a.min_lvl)
-----------------------------------------------------------------------------------------------------------------
-- 按姓名分取最小值
select * from jobs a where exists(select 1 from jobs b where a.job_desc=b.job_desc and b.min_lvl>a.min_lvl)
-------------------------------------------------------------------------------------------------------------------
--求一表中重复的值
select * from jobs a where exists(select 1 from jobs b where a.job_id>b.job_id and a.job_desc=b.job_desc and a.min_lvl=b.min_lvl)
----------------------------------------------------------------------------------------------------------------------
--查找两表中不同的内容
select * from jobs where not exists(select 1 from jobes where jobes.job_desc=jobs.job_desc)
本文介绍了几种实用的SQL查询方法,包括如何选取最大值、最小值、查找重复记录及对比不同表间的数据差异等。

636

被折叠的 条评论
为什么被折叠?



