SELECT
C.*
FROM
(
SELECT
A.*,
B.FLMC,
CASE
WHEN B.FLMC= '块' THEN
1
WHEN B.FLMC= '矿' THEN
2
WHEN B.FLMC= '球团' THEN
3
END num
FROM
(
SELECT
PK_INVBASDoC,
pk_deptdoc,
PK CHFL
FROM
qg wlcbdx
WHERE
pk cbdx IS NULL unionselect pk cbdx AS pk invbasdoc,
pk deptdoc,
PK CHFL
FROM
qg wlcbdxwhere pk cbdx IS NOT NULL
) A
LEFT JOIN OG CHFL B ON A.PK CHFL = B.PK CHFL
) C
ORDER BY c.num