mysql-三表關聯

ZHOU_VIP發表於2018-08-24
SELECT  t.USERID,
	t.USERNAME,
	t.USERPSWD,
	t.USERDESCP,
	t.USERTYPE,
	t.TENANTID,
	t.USERFLAG,
	r.TENANTNAME 
FROM t_cgs_sm_user t 
LEFT JOIN t_cgs_sys_tenant r ON t.TENANTID = r.TENANTID
WHERE t.USERTYPE <> 1 
UNION 
SELECT t.USERID,
	t.USERNAME,
	t.USERPSWD,
	t.USERDESCP,
	t.USERTYPE,
	t.TENANTID,
	t.USERFLAG,
	c.CUSTNAME AS TENANTNAME 
FROM t_cgs_sm_user t 
LEFT JOIN t_cgs_cust_base c ON t.TENANTID = c.CUSTID
WHERE t.USERTYPE = 1 
UNION
SELECT  t.USERID,
	t.USERNAME,
	t.USERPSWD,
	t.USERDESCP,
	t.USERTYPE,
	t.TENANTID,
	t.USERFLAG,
        b.TITLE AS TENANTNAME
FROM t_osm_user_project p
LEFT JOIN t_cgs_sm_user t ON p.USERID = t.USERID
LEFT JOIN t_osm_project_base b ON b.PROJECTID = p.PROJECTID

 

相關文章