关于mysql中sql语句的应用(待丰富)

如何获取某个字段里的最大值及明细?
SELECT * FORM 表格 WHERE 字段 IN (SELECT MAX(字段) FORM 表格 WHERE 你的条件)AND 你的条件,如:

select e.xxx as name ,e.xxx as email from hr_emp as e where e.LAST_HIRE_DT in (select max(xxx) from hr_emp where xxx=xxx) and xxx=xxx


多表关联查询

select p.NAME_FORMAT as name,e.DEPT_ID as department_id,po.DESCR as DESCR from hr_emp as e left join hr_personal as p on e.EMPL_ID=p.EMPL_ID left join hr_post as po on e.SETID_DEPT=po.SET_ID and e.C_QUARTERS_ID=po.C_QUARTERS_ID where xxx=xxx


重复数据及数量

select user_name,count(*) as count from user group by user_name having count>1;


表中某字段有多少不同的行

select count(DISTINCT xxx) as count from table;


发布了28 篇原创文章 · 获赞 1 · 访问量 629

猜你喜欢

转载自blog.csdn.net/c630843901/article/details/105180353