SET enable_mergejoin = off;
SET escape_string_warning = off;

SELECT
T1._Q_001_F_000,
T1._Q_001_F_001,
T1._Q_001_F_002RRef,
T1._Q_001_F_003RRef,
T1._Q_001_F_004RRef,
T1._Q_001_F_005RRef,
MAX(CASE WHEN (T1._Q_001_F_010 > CAST(0 AS NUMERIC)) THEN T2._Q_001_F_009RRef END),
MAX(T1._Q_001_F_010),
MAX(CASE WHEN (T1._Q_001_F_011 > CAST(0 AS NUMERIC)) THEN T2._Q_001_F_012RRef END),
MAX(CASE WHEN (T1._Q_001_F_011 > CAST(0 AS NUMERIC)) THEN T2._Q_001_F_011 ELSE FALSE END),
MAX(T1._Q_001_F_011),
CASE WHEN MAX(CASE WHEN (T1._Q_001_F_013 > CAST(0 AS NUMERIC)) THEN T2._Q_001_F_018_TYPE END) = '\\010'::bytea THEN SUBSTR(MAX(CASE WHEN (T1._Q_001_F_013 > CAST(0 AS NUMERIC)) THEN T2._Q_001_F_018_RTRef END || CASE WHEN (T1._Q_001_F_013 > CAST(0 AS NUMERIC)) THEN T2._Q_001_F_018_RRRef END),1,4) ELSE CASE WHEN MAX(CASE WHEN (T1._Q_001_F_013 > CAST(0 AS NUMERIC)) THEN T2._Q_001_F_018_TYPE END) IS NOT NULL THEN '\\000\\000\\000\\000'::bytea END END,
MAX(T1._Q_001_F_013),
MAX(T1._Q_001_F_014)
FROM t42 T1
LEFT OUTER JOIN t41 T2
ON (T1._Q_001_F_000 = T2._Q_001_F_000) AND (T1._Q_001_F_002RRef = T2._Q_001_F_002RRef) AND (T1._Q_001_F_003RRef = T2._Q_001_F_003RRef) AND (T1._Q_001_F_004RRef = T2._Q_001_F_004RRef) AND (T1._Q_001_F_005RRef = T2._Q_001_F_005RRef) AND (T1._Q_001_F_006 = T2._Q_001_F_006) AND (T1._Q_001_F_007 = T2._Q_001_F_049) AND (T1._Q_001_F_008 = T2._Q_001_F_050) AND (T1._Q_001_F_009 = T2._Q_001_F_051) AND (T1._Q_001_F_007 <> '0001-01-01 00:00:00'::timestamp)
GROUP BY T1._Q_001_F_000,
T1._Q_001_F_001,
T1._Q_001_F_002RRef,
T1._Q_001_F_003RRef,
T1._Q_001_F_004RRef,
T1._Q_001_F_005RRef
;
