我需要从特定字段的不同条件的表中获取值。对于特定域ID(domain_id),必须有多个用户名分配不同的system_id。
对于特定系统ID(123),列域(domain_id)应该具有活动用户名,仅以' a - '开头。 0r' A - '并且应禁用所有其他用户名,但用户名以' a - '开头。 0r' A - '。
请帮助获得预期结果;
我使用的查询如下:
SELECT e.domain_id, e.first_name, e.last_name, e.type, e.username,e.system_name
FROM (SELECT p.domain_id, p.first_name,p.last_name,p.type, u.username, u.status, u.system_id ,s.system_name
FROM ur_username u JOIN ur_username_person up ON u.username_id = up.username_id JOIN ur_person p ON up.person_id = p.person_id
JOIN ur_system s ON u.system_id = s.system_id
WHERE u.username LIKE 'A-%' OR username LIKE 'a-%'
AND u.status = 'ACTIVE'
AND u.system_id = 349 ) E
WHERE e.domain_id IN ( SELECT p.domain_id
FROM ur_username u
JOIN ur_username_person up ON u.username_id = up.username_id
JOIN ur_person p ON up.person_id = p.person_id
WHERE u.status = 'DISABLED'
AND u.system_id = 349 )