sql distinct
---沒有去除重復的記錄
select distinct ContractLaborEmployeeUidKey,ContractLaborEndDate from ContractLaborList order by ContractLaborEndDate desc
select * from ContractLaborList order by ContractLaborEmployeeUidKey
---沒有去除重復的記錄
select * from ContractLaborList where ContractLaborEmployeeUidKey in (select distinct ContractLaborEmployeeUidKey from ContractLaborList)
order by ContractLaborEndDate desc
--去除ContractLaborEmployeeUidKey重復的記錄
select * from ContractLaborList where ContractLaborEndDate in( SELECT MAX(ContractLaborEndDate) AS ContractLaborEndDate FROM ContractLaborList GROUP BY ContractLaborEmployeeUidKey) --重复行只查询一条
order by ContractLaborEndDate desc
---去除ContractLaborEmployeeUidKey重復的記錄
select * from ContractLaborList e
WHERE e.ContractLaborEndDate = (SELECT max(x.ContractLaborEndDate) FROM ContractLaborList x WHERE x.ContractLaborEmployeeUidKey = e.ContractLaborEmployeeUidKey);
SELECT * FROM View_ContractLaborList
--取出ContractLaborEmployeeUidKey重復的值
SELECT * FROM ContractLaborList s2
WHERE 1 < (SELECT COUNT(*) FROM ContractLaborList s1 WHERE s1.ContractLaborEmployeeUidKey = s2.ContractLaborEmployeeUidKey)
转载于:https://www.cnblogs.com/geovindu/archive/2012/10/31/2748586.html
文章最后发布于: 2019-07-13 02:29:19
相关阅读
初学者,仅供学习交流 Python学习两周时间了,这是我目前编写的比较满意的一个程序,有以下几个方面的经验总结:1.布局管理是可视化编程
PMM (Percona MySQL Monitor) 部署
部署环境说明mysql 10.0.0.201pmm server 10.0.0.200操作系统都是centos 7.x安装PMM安装dockeryum install docker运行dockersyst
一般写sql 是需要逻辑条件在里面的,首先求什么参数,在根据参数得到需要的参数,不能也要思路清晰明了,就是说想明白自己这个sql要做什
一、前期准备 安装系统:Windows8.1/64位 镜像:cn_sql_server_2012_enterprise_edition_with_sp1_x64_dvd_1234495.iso 64位下载:htt
MySQL中order by 和 group by 一起使用
select * from (select * from crm_followup order by CreateTime desc) a GROUP BY a.CDID