SELECT
	*
FROM
	ct_user
WHERE
	ORG_ID IN (
		SELECT
			ORG_ID
		FROM
			CT_ORGANIZATION
		WHERE
			ORG_TYPE IN (0, 1, 2)
		AND (
			parent_name LIKE '%第四分公司%'
			OR ORG_NAME LIKE '%第四分公司%'
		)
	)

---  检索符合条件的原始数据
SELECT * from  sys_dept  where target_id_sync in(

	SELECT
			ORG_ID
		FROM
			scyy.CT_ORGANIZATION
		WHERE
			ORG_TYPE IN (0, 1, 2)
		AND (
			parent_name LIKE '%第四分公司%'
			OR ORG_NAME LIKE '%第四分公司%'
		)
)

--- 查询未同步用户信息

SELECT
	*
FROM
	scyy.ct_user
WHERE
	ORG_ID IN (
		SELECT
			ORG_ID
		FROM
			scyy.CT_ORGANIZATION
		WHERE
			ORG_TYPE IN (0, 1, 2)
		AND (
			parent_name LIKE '%第四分公司%'
			OR ORG_NAME LIKE '%第四分公司%'
		)
	)
AND USER_ID NOT IN (
	SELECT
		targetid
	FROM
		sys_user
	WHERE
		deptid IN (
			SELECT
				id
			FROM
				sys_dept
			WHERE
				target_id_sync IN (
					SELECT
						ORG_ID
					FROM
						scyy.CT_ORGANIZATION
					WHERE
						ORG_TYPE IN (0, 1, 2)
					AND (
						parent_name LIKE '%第四分公司%'
						OR ORG_NAME LIKE '%第四分公司%'
					)
				)
		)
)
--查询一类设备相关数据
SELECT * from eq_equip_rq where EQ_CATEGORY = 3

--查询有效一类设备
SELECT
	EQ_CODE,
	EQ_SBMC,
	LNG,
	LAT,
	EQ_AREA,
	EQ_LOC,
	PROPERTY_UNIT,
	EQ_USE_DEPT,
	TYPE_CODE,
	PROPERTY_UNIT_EMP,
	PROPERTY_UNIT_PHONE,
'${batchId}' as batchId
FROM
	eq_equip_rq
WHERE
	EQ_CATEGORY = 3
AND EQ_USE_DEPT is not NULL
--设备需要
AND EQ_LOCNO LIKE 'N%';


SELECT * FROM scyy.eq_equip_rq WHERE EQ_LOCNO = 'N37A199' AND 	EQ_CATEGORY = 3
AND ORG_CODE is not NULL AND ORG_CODE !='';
select WELL_CODE from bus_sync_well_info GROUP BY WELL_CODE HAVING COUNT(1) >1

--查询库中存在但同步未获取的井信息
select * from bus_well_info
WHERE WELL_CODE not in(
select WELL_CODE FROM bus_sync_well_info
)
AND WELL_CODE in(
SELECT EQ_LOCNO from scyy.eq_equip_rq WHERE EQ_CATEGORY = 3
)
--备份井在原生产运行中的井信息
 SELECT * from scyy.eq_equip_rq WHERE EQ_CATEGORY = 3
AND EQ_LOCNO in (
SELECT EQ_LOCNO FROM
other_well_info)


--查询井维护组织信息
SELECT
	*
FROM
	sys_dept
WHERE
	id IN ( SELECT RESPONSIBLE_DEPT FROM bus_well_info GROUP BY RESPONSIBLE_DEPT )

SELECT
	*
FROM
	sys_dept
WHERE
	id IN ( SELECT DEPTID FROM bus_well_info GROUP BY DEPTID )
