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

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

WBOY
Release: 2016-06-07 14:53:45
Original
992 people have browsed it

多条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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template