Home >Database >Mysql Tutorial >多条ID对应关系表只查一条

多条ID对应关系表只查一条

WBOY
WBOYOriginal
2016-06-07 14:53:45988browse

多条ID对应关系表只查一条 假如公司表 -----员工信息表 www.2cto.com ORGID --USERID USERID--USERINFO 关系一对多... 想要查询 每个公司只显示一个员工号 SELECT * FROM ( SELECT A.*,ROW_NUMBER() OVER (PARTITION BY orgid ORDER BY A.USERID) RN FROM us


多条ID对应关系表只查一条

 

假如公司表  -----员工信息表 

  www.2cto.com  

ORGID --USERID           USERID--USERINFO 

 

关系一对多... 

 

想要查询  每个公司只显示一个员工号 

 

SELECT *  FROM 

SELECT A.*,ROW_NUMBER() OVER (PARTITION BY orgid ORDER BY A.USERID) RN 

FROM usr A 

WHERE RN=1

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn